如何使用库 "rworldmap" 在 Shiny R 上绘制地图
How to plot map on Shiny R using library "rworldmap"
虽然我可以在降价时使用我的数据和 rworldmap 生成漂亮的地图,但无法使用 Shiny R 实现相同的地图。请帮忙。
我的代码片段:
# Join data to a map to create a spatialPolygonsDataFrame
sPDF <- joinCountryData2Map(comb_mdata, joinCode='NAME', nameJoinColumn='Country')
par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i")
mapParams <- mapCountryData(sPDF, nameColumnToPlot='Wt.Score',
mapRegion="world",
missingCountryCol='dark grey', numCats=10,
colourPalette=c('green4','green1','greenyellow','yellow','yellow2','orange','coral','red','red3','red4'),
addLegend=FALSE,
oceanCol="light blue")
do.call(addMapLegend, c(mapParams, legendWidth=1.0, legendIntervals="page", legendMar=3))
mtext("[Grey Color: No Data Available]",side=1,line=-41)
我终于能够解决我的问题,这可能会帮助有需要的人:
ui.R:
mainPanel(
tabsetPanel(id="tp",
tabPanel("Map View", plotOutput("mPlot", height="560px", width="950px"))
)
)
server.R:
# Join data frame 'comb_mdata' to the map
sPDF <- joinCountryData2Map(comb_mdata, joinCode='NAME', nameJoinColumn='Country')
# Generate the Map
output$mPlot <- renderPlot({
mapParams <- mapPolys(sPDF, nameColumnToPlot='Wt_Score', mapRegion='world',
missingCountryCol='dark grey', numCats=10,
colourPalette=c('green4','green1','greenyellow','yellow','yellow2','orange','coral','red','red3','red4'),
addLegend=TRUE,
oceanCol='light blue')
mtext("[Grey Color: No Data Available]",side=1,line=-1)
})
虽然我可以在降价时使用我的数据和 rworldmap 生成漂亮的地图,但无法使用 Shiny R 实现相同的地图。请帮忙。
我的代码片段:
# Join data to a map to create a spatialPolygonsDataFrame
sPDF <- joinCountryData2Map(comb_mdata, joinCode='NAME', nameJoinColumn='Country')
par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i")
mapParams <- mapCountryData(sPDF, nameColumnToPlot='Wt.Score',
mapRegion="world",
missingCountryCol='dark grey', numCats=10,
colourPalette=c('green4','green1','greenyellow','yellow','yellow2','orange','coral','red','red3','red4'),
addLegend=FALSE,
oceanCol="light blue")
do.call(addMapLegend, c(mapParams, legendWidth=1.0, legendIntervals="page", legendMar=3))
mtext("[Grey Color: No Data Available]",side=1,line=-41)
我终于能够解决我的问题,这可能会帮助有需要的人:
ui.R:
mainPanel(
tabsetPanel(id="tp",
tabPanel("Map View", plotOutput("mPlot", height="560px", width="950px"))
)
)
server.R:
# Join data frame 'comb_mdata' to the map
sPDF <- joinCountryData2Map(comb_mdata, joinCode='NAME', nameJoinColumn='Country')
# Generate the Map
output$mPlot <- renderPlot({
mapParams <- mapPolys(sPDF, nameColumnToPlot='Wt_Score', mapRegion='world',
missingCountryCol='dark grey', numCats=10,
colourPalette=c('green4','green1','greenyellow','yellow','yellow2','orange','coral','red','red3','red4'),
addLegend=TRUE,
oceanCol='light blue')
mtext("[Grey Color: No Data Available]",side=1,line=-1)
})