gpt4 book ai didi

r - World Map - Plotting Circles,与 No of 相关的圆圈大小

转载 作者:行者123 更新时间:2023-12-05 00:00:04 26 4
gpt4 key购买 nike

我希望能够在与文档数量相关的图表上创建一个带有圆圈的世界地图。

这是我尝试使用 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

所以问题是你能帮我修复代码以正确绘制数据吗?

干杯,
杰斯

最佳答案

您可以在 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")

关于r - World Map - Plotting Circles,与 No of 相关的圆圈大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10751326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com