我有这样的数据集(pts):
x <- seq(-124.25,length=115,by=0.5)
y <- seq(26.25,length=46,by=0.5)
z <- 1:5290
w <- rep(1:5,1058)
longlat <- expand.grid(x = x, y = y)
pts <- data.frame(longlat,z,w)
names(pts) <- c( "lon","lat","data","class")
我需要展示的是“数据”,它是最大值,以及同一美国地图上“类”的类别。
有人能给我一些想法吗?非常感谢。
答案 0 :(得分:1)
这是我到目前为止所拥有的:
x <- seq(-124.25,length=115,by=0.5)
y <- seq(26.25,length=46,by=0.5)
z <- 1:5290
w <- rep(1:5,1058)
longlat <- expand.grid(x = x, y = y)
pts <- data.frame(longlat,z,w)
names(pts) <- c( "lon","lat","data","class")
require('ggmap')
base.map.in <- get_map(location = c(min(x),
min(y),
max(x),
max(y)),
source = "osm")
# create the map object
theme_set(theme_bw(base_size = 8))
my.map <- ggmap(base.map.in) %+% pts +
aes(x = lon,
y = lat) +
geom_point(aes(color = as.factor(class),
size = data),
alpha = 0.5) +
scale_size(range = c(0.5,2))
print(my.map)
ggsave(filename = "classmap.png",
plot = my.map,
scale = 1,
width = 6, height = 3,
dpi = 300)
这给了我这个情节:
答案 1 :(得分:0)
正如LostBrit建议的那样,为什么不试试ggmap?
library(ggmap)
usmap <- ggmap(get_map(location = "US", zoom=4))
usmap + geom_point(data=pts, aes(x=lon, y=lat, size=data, color=class))
从那里,您可以使用抖动和alpha来修复过度绘图。如果您首先将形状转换为as.factor()