MENU

Fun & Interesting

Introduction to the plotly Package in R (Example) | Draw Interactive Plots | Create Web-Based Graphs

Statistics Globe 6,207 lượt xem 3 years ago
Video Not Working? Fix It Now

How to use the plotly package as an alternative graphing library to ggplot2 using JavaScript to render the final graphics in the R programming language. More details: https://statisticsglobe.com/plotly-r-package
R code of this video:

df <- mtcars
df$name <- row.names(mtcars)

install.packages("plotly")
library(plotly)

plot_ly(
data = df,
x = ~cyl,
y = ~disp
)

plot_ly(
data = df,
x = ~cyl,
y = ~disp,
type = "scatter",
mode = "markers"
)

plot_ly(
data = df,
x = ~cyl,
y = ~disp,
color = ~factor(cyl),
type = "scatter",
mode = "markers"
)

plot_ly(
data = df,
x = ~cyl,
y = ~disp,
color = ~factor(cyl),
text = ~name,
type = "scatter",
mode = "markers"
)

fig <- ggplot2::ggplot(data = df, aes(x=cyl, y=disp)) + geom_point(aes(color = factor(cyl)))
ggplotly(fig)

Follow me on Social Media:
Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook – Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
Twitter: https://twitter.com/JoachimSchork

Comment