First, let’s plot a simple non interactive plot of the sleep vs bodyweight
library(ggplot2)
data(msleep)
p=ggplot(msleep,aes(x=bodywt,y=sleep_total, label=name))+
geom_point(aes(color=vore),size=2)+
geom_smooth()+
scale_x_log10()
p
FALSE `geom_smooth()` using method = 'loess' and formula 'y ~ x'
And now let’s plot the interactive graph using plotly:
library(plotly)
FALSE
FALSE Attaching package: 'plotly'
FALSE The following object is masked from 'package:ggplot2':
FALSE
FALSE last_plot
FALSE The following object is masked from 'package:stats':
FALSE
FALSE filter
FALSE The following object is masked from 'package:graphics':
FALSE
FALSE layout
ply <- ggplotly(p)
FALSE `geom_smooth()` using method = 'loess' and formula 'y ~ x'
ply