R plotly Choropleth不打印数据
我试图继续学习教程,但不知道如何将它与另一个geojson一起使用,该geojson是关于德国政府提供的新冠病毒-19数据的R plotly Choropleth不打印数据,r,plotly,choropleth,R,Plotly,Choropleth,我试图继续学习教程,但不知道如何将它与另一个geojson一起使用,该geojson是关于德国政府提供的新冠病毒-19数据的 library(plotly) library(rjson) url <- 'https://raw.githubusercontent.com/Johannes96/Coropleth/main/RKI_Corona_Bundeslaender_2.geojson' geojson <- rjson::fromJSON(file=url) url2<
library(plotly)
library(rjson)
url <- 'https://raw.githubusercontent.com/Johannes96/Coropleth/main/RKI_Corona_Bundeslaender_2.geojson'
geojson <- rjson::fromJSON(file=url)
url2<- "https://raw.githubusercontent.com/Johannes96/Coropleth/main/RKI_Corona_Bundeslaender.csv"
df <- read.csv(url2)
g <- list(
fitbounds = "locations",
visible = FALSE
)
fig <- plot_ly()
fig <- fig %>% add_trace(
type="choroplethmapbox",
geojson=geojson,
locations=df$ObjectId,
z=df$AnzahlFall,
colorscale="Viridis",
featureidkey="properties.OBJECTID_1"
)
fig <- fig %>% colorbar(title = "covid-19 cases germany")
fig <- fig %>% layout(
mapbox=list(
style="carto-positron",
zoom =5,
center=list(lon=9.7, lat=50))
)
fig
library(plotly)
图书馆(rjson)
url您调用的df列为false,用ObjectId_1替换ObjectId,用AnzahlFall替换Fallzahl,例如:
library(plotly)
library(rjson)
url <- 'https://raw.githubusercontent.com/Johannes96/Coropleth/main/RKI_Corona_Bundeslaender_2.geojson'
geojson <- rjson::fromJSON(file=url)
url2<- "https://raw.githubusercontent.com/Johannes96/Coropleth/main/RKI_Corona_Bundeslaender.csv"
df <- read.csv(url2)
g <- list(
fitbounds = "locations",
visible = FALSE
)
fig <- plot_ly()
fig <- fig %>% add_trace(
type="choroplethmapbox",
geojson=geojson,
locations=df$OBJECTID_1,
z=df$Fallzahl,
colorscale="Viridis",
featureidkey="properties.OBJECTID_1"
)
fig <- fig %>% colorbar(title = "covid-19 cases germany")
fig <- fig %>% layout(
mapbox=list(
style="carto-positron",
zoom =5,
center=list(lon=9.7, lat=50))
)
fig
library(plotly)
图书馆(rjson)
嗨,你说得对。然而,它仍然不起作用。只是显示一张空地图。你能把从strart到你用来得到这个输出的全部代码都贴出来吗?它显示的唯一警告是“没有找到要修改的颜色条”。刚刚编辑了它,我以前只放了要修改的部分,其余的都没问题。真奇怪。现在我执行了上面的代码,但仍然无法工作。我只是把代码放在RStudio中并执行它,当它完成加载后,它只会再次显示一个空映射。。。我做错了什么?我想是时候放弃了……嗯,奇怪,你的packageVersion(“plotly”)
packageVersion(“rjson”)
?不要放弃