2017-07-26 89 views
0

我想使用的功能ggplotly錯誤ggplotly:嘗試應用非功能

這裏產生互動ggplot圖是我的代碼:

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) 

但是,錯誤顯示爲後最後codeg gplotly(p)

錯誤gg2list(p,寬度=寬度,高度=高度,工具提示=工具提示, :嘗試應用非功能

任何想法來解決這個問題?

回答

0

改爲使用plotly_build。以下代碼在我的電腦上工作:

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) 
+0

thx。@Sal,但同樣的錯誤仍然顯示 – exteralvictor

+0

什麼是您的軟件包版本?我正在windows 7機器上運行plotly_4.6.0和ggplot2_2.2.1。嘗試在rstudio/r控制檯上運行'sessionInfo()',並在必要時更新軟件包。 – Sal

+0

尊敬的朋友,在更新所有軟件包後,不需要使用'plotly_build(p)','ggplotly(p)'。應該提到的是,建議使用'install_github(「hadley/ggplot2」)更新ggplot2' – exteralvictor

相關問題