簡體   English   中英

如何使用庫“ rworldmap”在Shiny R上繪制地圖

[英]How to plot map on Shiny R using library “rworldmap”

雖然我可以將我的數據與Markdown上的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)
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM