我有一个 Plotly 帐户和一个 R 脚本,创建了一个我想在我的 Plotly 页面上发布的情节。在查看了 Plotly Getting Started 页面和其他一些在线建议后,我最终得到了这段代码。
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)
Run Code Online (Sandbox Code Playgroud)
但是,当我执行代码时会出现此错误:
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")
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题并发布我的情节?我还尝试了以下方法:
ggplotly(plot_region)
Run Code Online (Sandbox Code Playgroud)
但它出现了这个错误:
Error in `[[<-.data.frame`(`*tmp*`, a, value = c("?????? ??????", :
replacement has 483 rows, data has 13
Run Code Online (Sandbox Code Playgroud)
您的语法是正确的,在这种情况下,从到 的ggplotly转换似乎失败了。我在这里报告了该错误:https ://github.com/ropensci/plotly/issues/278ggplotplotly
另一种解决方案是使用plotly 的原生 R 语法创建图形。这是您的数据的示例:
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')
Run Code Online (Sandbox Code Playgroud)
创建此图: https: //plot.ly/~christopherp/1129

(来源:plot.ly 的 christopherp)
| 归档时间: |
|
| 查看次数: |
1837 次 |
| 最近记录: |