【问题标题】:Plotly - Publishing my plot with RPlotly - 用 R 发布我的情节
【发布时间】:2015-11-29 17:34:58
【问题描述】:

我有一个 Plotly 帐户和一个 R 脚本,它创建了一个我想在我的 Plotly 页面上发布的情节。在查看了 Plotly 入门页面和其他一些在线建议后,我最终得到了这段代码。

library(XLConnect)
library(dplyr)
library(ggplot2)
library(devtools)
library(plotly)

##Preparing the data file
myurl <-     "http://minagric.gr/images/stories/docs/agrotis/Elia/egekrimenes_typop_monades220715.xls"
temp <- file.path(getwd(), "temp.xls")
download.file(myurl,temp)
mydata <- readWorksheetFromFile(temp, sheet=1, header = TRUE, startRow = 2)
colnames(mydata)<-c("name", "approval_code", "region", "prefecture")

plot_region <- ggplot(mydata,aes(x=region)) + 
      geom_histogram(fill="lightblue") +
      theme(plot.title = element_text(size=15, face="bold", vjust=2),     axis.text.x=element_text(angle=50, size=5, vjust=0.35)) +
      labs(title = "Olive oil plants per Region") + 
      xlab("Region") + ylab("Number of plants")
py <- plotly(username = "myusername", key = "mykey")    
response<-py$ggplotly(plot_region)

但是,当我执行代码时会出现此错误:

Error in eval(expr, envir, enclos) : attempt to apply non-function
In addition: Warning messages:
1: 'plotly' is deprecated.
Use 'ggplotly' instead.
See help("Deprecated") 
2: 'plotly' is deprecated.
Use 'plot_ly' instead.
See help("Deprecated") 

我该如何解决这个问题并发布我的图?我还尝试了以下方法:

ggplotly(plot_region)

但它会出现此错误:

Error in `[[<-.data.frame`(`*tmp*`, a, value = c("ΣΤΕΡΕΑ ΕΛΛΑΔΑ",  : 
  replacement has 483 rows, data has 13

【问题讨论】:

    标签: r ggplot2 plotly


    【解决方案1】:

    您的ggplotly 语法是正确的,在这种情况下,从ggplotplotly 的转换似乎失败了。我在这里报告了这个错误:https://github.com/ropensci/plotly/issues/278

    另一种解决方案是使用plotly's native R syntax 创建图形。以下是您的数据示例:

    plot_ly(mydata, x=region, type="histogram", filename="olive oil plants per region") %>%     
        layout(xaxis=list(title='Region'),
               yaxis=list(title='Number of plants'),
               margin=list(b=100), # expand the bottom margin a bit to accommodate the long labels
               title='Olive oil plants per region')
    

    创建此图:https://plot.ly/~christopherp/1129
    (来源:christopherp at plot.ly

    More histogram examples

    【讨论】:

      猜你喜欢
      • 2018-02-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      • 2021-05-16
      • 2018-05-15
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      相关资源
      最近更新 更多