简体   繁体   English

在地图上绘制的条

[英]Bars to be plotted over map

I want to draw barchart over map as on this page: http://docs.oracle.com/cd/E16162_01/web.1112/e16181/dv_map.htm#BEHHAFEJ 我要按此页面上的地图绘制条形图: http ://docs.oracle.com/cd/E16162_01/web.1112/e16181/dv_map.htm#BEHHAFEJ

例

I used following data and code but it is not working. 我使用了以下数据和代码,但无法正常工作。

ddf = read.table(header=T, sep=",", text="
country, val1, val2, val3
Nigeria,5,10,8
China,8,12,20
Brazil,15,9,20
Italy,9,25,5
Australia,15,5,25
")

require (rworldmap)

sPDF <- joinCountryData2Map(ddf
    , joinCode = "NAME"
    , nameJoinColumn = "country"
    , verbose = TRUE)

mapBars( sPDF, 
       , nameZs=c(ddf$val1, ddf$val2, ddf$val3)
       , symbolSize=4 )

How can I correct this? 我该如何纠正? Please help. 请帮忙。


Edit: I tried using code in answer below but I am getting an empty window plot with error: Error in par(plt = c(xyx, xyy), new = TRUE) : invalid value specified for graphical parameter "plt" 编辑:我尝试在下面的答案中使用代码,但出现错误的空窗口图:par(plt = c(xyx,xyy),new = TRUE)中的错误:为图形参数“ plt”指定的值无效 在此处输入图片说明

You could try using subplots: 您可以尝试使用子图:

# ...
plot(getMap())
df <- merge(x=ddf, y=sPDF@data[sPDF@data$ADMIN, c("ADMIN", "LON", "LAT")], by.x="country", by.y="ADMIN", all.x=TRUE)
require(TeachingDemos)
for (i in 1:nrow(df)) 
  subplot(barplot(height=as.numeric(as.character(unlist(df[i, 2:4], use.names=F))), 
                  axes=F, 
                  col=rainbow(3), ylim=range(df[,2:4])),
          x=df[i, 'LON'], y=df[i, 'LAT'], size=c(.3, .3))
legend("topright", legend=names(df[, 2:4]), fill=rainbow(3))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM