我正在尝试使用此页面上的代码制作堆叠条形图: Bars to plotted over map
但是下面包含 beside=FALSE 的代码仍然绘制并排的条形图,而不是堆叠的条形图。
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)
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, beside=FALSE,
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))
可能是什么原因,我该如何解决?