gpt4 book ai didi

r - Plotly - 用 R 发布我的 plotly

转载 作者:行者123 更新时间:2023-12-03 20:23:09 25 4
gpt4 key购买 nike

我有一个 Plotly 帐户和一个 R 脚本,创建了一个我想在我的 Plotly 页面上发布的 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)

但是,当我执行代码时会出现此错误:
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")

我怎样才能解决这个问题并发布我的 plotly ?我还尝试了以下方法:
ggplotly(plot_region)

但它出现了这个错误:
Error in `[[<-.data.frame`(`*tmp*`, a, value = c("ΣΤΕΡΕΑ ΕΛΛΑΔΑ",  : 
replacement has 483 rows, data has 13

最佳答案

您的 ggplotly语法正确,看起来像是从 ggplot 转换而来的至 plotly本案失败。我在这里报告了这个错误: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
Example of a histogram in R created with Plotly
(来源: christopherp at plot.ly)
More histogram examples

关于r - Plotly - 用 R 发布我的 plotly ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32383155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com