R ggplot2地图上的多个站点
我试图在ggplot地图上绘制我的所有站点。我有5个位置,每个位置有多个站点,但当我尝试绘制所有站点时,每个位置只显示一个点,而不是每个站点显示一个点。我有34个站点和5个位置,所以我需要一张有34个点而不是5个点的地图!任何帮助都将不胜感激!非常感谢 这些是y和x作为我的long和lat的数据R ggplot2地图上的多个站点,r,ggplot2,R,Ggplot2,我试图在ggplot地图上绘制我的所有站点。我有5个位置,每个位置有多个站点,但当我尝试绘制所有站点时,每个位置只显示一个点,而不是每个站点显示一个点。我有34个站点和5个位置,所以我需要一张有34个点而不是5个点的地图!任何帮助都将不胜感激!非常感谢 这些是y和x作为我的long和lat的数据 位置 关岛GFA 201.09952 144.8786111 13.495 关岛GFA2 179.04171 144.6597222 13.41638889 关岛GFA3 67.66379 144.2
<代码>位置 关岛GFA 201.09952 144.8786111 13.495 关岛GFA2 179.04171 144.6597222 13.41638889 关岛GFA3 67.66379 144.2761111 13.47333 关岛GFB1 201.09952 144.7105556 13.31416667 关岛GFB2 179.04171 144.655 13.50194444 关岛GFB3 67.66379 144.8697222 13.37472222
我需要为关岛绘制所有6个站点。这是我正在使用的代码和最终输出map.world <- map_data(map="world")
gg <- ggplot()
gg <- gg + theme(legend.position="none")
gg <- gg + geom_map(data=map.world, map=map.world, aes(map_id=region, x=long, y=lat), fill="white", colour="black", size=0.25) + theme_bw()
gg
par<-read.csv("parmap.csv", header=T)
head(par)
g<-gg+ geom_polygon() +
geom_point(data=par, aes(x = y, y = x, color=PAR)) +theme_minimal()
g
map.world在本例中,您可能需要在兴趣点(即“关岛”)附近缩放地图
一种方法如下所示
library(ggplot2)
library(ggmap)
#get the map
center = paste(min(df$lat)+(max(df$lat)-min(df$lat))/2,
min(df$lon)+(max(df$lon)-min(df$lon))/2, sep=" ")
map <- get_map(location = center, maptype = "roadmap", zoom = 8, source = "google", color="bw")
p <- ggmap(map)
#plot points on the map
plt <- p +
geom_point(data=df, aes(x = lon, y = lat, color = PAR)) +
scale_color_gradientn(colours = rainbow(10)) +
theme_minimal()
plt
@Sathish非常感谢您编辑我的代码使用您发布的示例数据,所有六个站点都已绘制。当你绘制完整的世界地图时,它们是如此的紧密,以至于这些点出现在彼此的顶部。哦,非常感谢!那么应该如何编辑来显示网站呢?非常感谢@Prem!GF其实是我的网站!因此,它保持着色点的网站,而不是按标准…而且它不允许我从其他位置绘制站点。对不起,我对这一点很陌生。我如何最终放大我创建的地图以显示我的所有点?非常感谢。
df <- structure(list(Location = c("Guam", "Guam", "Guam", "Guam", "Guam",
"Guam", "N_Mariana_Islands"), sites = c("GFA", "GFA2", "GFA3",
"GFB1", "GFB2", "GFB3", "NMI1"), PAR = c(201.09952, 179.04171,
67.66379, 201.09952, 179.04171, 67.66379, 100), lon = c(144.8786111,
144.6597222, 144.2761111, 144.7105556, 144.655, 144.8697222,
145.192522), lat = c(13.495, 13.41638889, 13.47333333, 13.31416667,
13.50194444, 13.37472222, 14.150817)), .Names = c("Location",
"sites", "PAR", "lon", "lat"), class = "data.frame", row.names = c(NA,
-7L))
# Location sites PAR lon lat
#1 Guam GFA 201.09952 144.8786 13.49500
#2 Guam GFA2 179.04171 144.6597 13.41639
#3 Guam GFA3 67.66379 144.2761 13.47333
#4 Guam GFB1 201.09952 144.7106 13.31417
#5 Guam GFB2 179.04171 144.6550 13.50194
#6 Guam GFB3 67.66379 144.8697 13.37472
#7 N_Mariana_Islands NMI1 100.00000 145.1925 14.15082