I would like to produce interactive ggplot graph using the function ggplotly
Here is my code:
set.seed(100)
d <- diamonds[sample(nrow(diamonds),1000),]
p <- ggplot(data = d,aes(x=carat,y=price))+
geom_point(aes(text=paste("Clarity:",clarity)),size = 4)+
geom_smooth(aes(color = cut,fill=cut))+facet_wrap(~cut)
gg <- ggplotly(p)
However, the error shows up as after the last codeg gplotly(p)
:
Error in gg2list(p, width = width, height = height, tooltip = tooltip, : attempt to apply non-function
Any idea to fix the problem?
Use plotly_build
instead. The following code works on my pc:
set.seed(100)
d <- diamonds[sample(nrow(diamonds),1000),]
p <- ggplot(data = d,aes(x=carat,y=price))+
geom_point(aes(text=paste("Clarity:",clarity)),size = 4)+
geom_smooth(aes(color = cut,fill=cut))+facet_wrap(~cut)
gg <- plotly_build(p)
print(gg)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.