2012-05-25 61 views
4

相关的圈的大小我希望能够创建一个世界地图,在与图表相关的图上有圆圈。世界地图 - 绘图圈,圈的大小与

这个我试图使用mapBubbles,但是当绘制图表时出了点问题。

我的数据文件如下:

ISO3V10 Country No of Documents Lat Lon 
ARG  Argentina 41   -64 -34 
AUS  Australia 224   133 -27 
CAN  Canada  426   -95 60 
IRL  Ireland 68   -8 53 
ITA  Italy    583   12.8333 42.8333 
NLD  Netherlands 327   5.75 52.5 
NZL  New Zealand 26   174 -41 
ESP  Spain    325   -4 40 
GBR  United Kingdom 2849    -2 54 
USA  United States 3162   -97 38 

我写的代码如下:

# Thanks to Andrie for the reproducible code and Paolo for the suggested edit 

zz <-"ISO3V10 Country No.of.Documents Lat Lon 
ARG Argentina 41 -64 -34 
AUS Australia 224 133 -27 
CAN Canada 426 -95 60 
IRL Ireland 68 -8 53 
ITA Italy 583 12.8333 42.8333 
NLD Netherlands 327 5.75 52.5 
NZL 'New Zealand' 26 174 -41 
ESP Spain 325 -4 40 
GBR 'United Kingdom' 2849 -2 54 
USA 'United States' 3162 -97 38 
" 

dF2 <- read.table(textConnection(zz), header = TRUE) 

# dF2 <- read.delim(file="C:\\Users\\js207963\\Documents\\noofpublications_AllUpdated.txt", header = TRUE, sep = "\t") 
dF2[] 
par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") 
mapBubbles(dF2=getMap(), nameZSize="No.of.Documents", nameZColour="Country",oceanCol="lightblue", landCol="wheat", addLegend=FALSE 

所以,问题是你能帮助我解决了代码,以绘制数据是否正确?

干杯, 杰斯

+0

这可能是最好的,如果你坚持一个帐户的计算器。 – BenBarnes

+0

我甚至不知道我有2个帐户! –

回答

1

你需要更多的信息传递给mapBubbles功能,因为您的数据帧不是SpatialPolygonsDataFrame。以下应工作(你LatLon可能被贴错标签):

mapBubbles(dF=dF2, nameZSize="No.of.Documents", 
    nameZColour="Country",oceanCol="lightblue", landCol="wheat", 
    addLegend=FALSE, nameX = "Lat", nameY = "Lon") 

以上,nameXnameY被传递给函数,以指示绘制的气泡。此外,将数据帧dF2传递给参数dF,而不是调用getMap()

编辑:

我也很喜欢Andrie的答案与ggplot2(除其他事项外,空间比下面的图形更好的使用),但既然你已经明确使用rworldmap发布的其他问题,我想它适合坚持这个包。

World Map with bubbles

+0

这个作品很棒,是否有消除传说或使它变小?当我放大欧洲的时候,这个传说依然存在,而且价值观也会重演,这可能会引起争议! –

+0

为避免绘制按国家颜色编码的图例,请在'mapBubbles'的参数中添加'addColourLegend = FALSE'。为了让图例更小,看起来你可能需要调整'mapBubbles'函数或者在绘图后通过调用addMapLegendBoxes来添加图例。 – BenBarnes

+0

@JessSheasby,抱歉忘记包含您的用户名,以便通知您。请参阅上面的评论:) – BenBarnes

6

您可以使用ggplot绘制这样的:

enter image description here

重建数据:

dat <- read.table(text=" 
ISO3V10 Country 'No of Documents' Lat Lon 
ARG  Argentina 41   -64 -34 
AUS  Australia 224   133 -27 
CAN  Canada  426   -95 60 
IRL  Ireland 68   -8 53 
ITA  Italy    583   12.8333 42.8333 
NLD  Netherlands 327   5.75 52.5 
NZL  'New Zealand' 26   174 -41 
ESP  Spain    325   -4 40 
GBR  'United Kingdom' 2849    -2 54 
USA  'United States' 3162   -97 38 
", header=TRUE) 

负载包和情节:

library(ggplot2) 
library(maps) 

mdat <- map_data('world') 

str(mdat) 
ggplot() + 
    geom_polygon(dat=mdat, aes(long, lat, group=group), fill="grey50") + 
    geom_point(data=dat, 
      aes(x=Lat, y=Lon, map_id=Country, size=`No.of.Documents`), col="red") 
+0

当我使用上面的代码时我得到这个错误信息:'eval(expr,envir,enclos)中的错误:object'long'not found'任何想法什么是错的? –

+1

@JessSheasby我刚刚在一个干净的R会话中运行此代码,它适用于我。我很抱歉,但我不知道你的情况发生了什么。 – Andrie

+0

仍然不能得到这个工作,虽然:( –