r - 使用 plotly::api_create 和 ggplot2::geom_sf 函数时文件太大

标签 r plotly shapefile sf

我正在尝试使用 R 中的 plotly 在线绘制空间数据,但我收到一条错误消息“请求实体太大此文件太大!您当前的订阅限制为 524 KB 上传。”关于如何解决这个问题的任何线索?为了重现我的代码,您需要 (i) 在 plotly 上注册和 (ii) 在我的 github repo 上下载法语系的 shapefile .这 3 个文件应位于名为 shapefile 的文件夹中。在我看来,ggplot2 函数 geom_sf 生成的文件太大。我的代码在下面

require(tidyverse)
require(ggplot2)

#Info required for online plotting 
Sys.setenv("plotly_username"="replace_by_your_username")
Sys.setenv("plotly_api_key"="replace_by_your_apikey")

#Read shapefile
dep <- sf::st_read("replace_with_the_correctPATH/shapefile/DEPARTEMENT.shp")

#Variable to plot
zz<-runif(length(dep$CODE_DEPT),-10,3)

#ggplot2 object
gg <- dep %>%
mutate(discrete = cut(zz, c(-10, seq(-3, 3, by = 1)))) %>%
ggplot() +
geom_sf(aes(fill = discrete, text = paste("Department:", dep$CODE_DEPT, "<br>", "bli", zz))) +
scale_fill_brewer(palette = "PuOr", name = "bla")

#Plotting the figure on your local computer works
#plotly::ggplotly(gg, tooltip = c("text"))

#Generate an error message
plotly::api_create(gg, tooltip = c("text"),filename = "sthing")

最佳答案

这似乎不是您的问题,但我也遇到过同样的事情。对于 future 的读者,我的问题似乎是我使用的数据框(比如 100 行)是一个大于文件限制的大型数据集(15,000 行)的子集。

虽然我的子集非常小并且完全在上传限制之内,但我必须将子集保存为 csv,将其重新加载并使用新加载的数据框作为我的 plotly 上传。尽管导入的数据框与子集数据框的行数相同,但我不得不断开子集与原始较大数据集的连接,不知道为什么。

关于r - 使用 plotly::api_create 和 ggplot2::geom_sf 函数时文件太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52482085/

相关文章:

r - 如何将 lubridate as_datetime 函数与 dplyr mutate 和 case_when 函数结合使用?

r - 如何比较唯一值的数量

python - 如何在 python 中绘制具有多个 y 轴的分组条形图

r - 将 shp 文件(sf 对象)转换为 osm pbf?

RSelenium错误: Can't Connect to Host; Selenium Server is not running

r - 在起点和终点之间过滤

r - 如何使用 R 获取距离点最近的关联多边形的信息?

python - python 中 3D 多边形的交点

python - 创建一个 Plotly 按钮以在 ScatterPlot 中隐藏/显示数据点

javascript - 如何在plotly.js中为图例赋予固定宽度