0

我有这样的数据集(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")

我需要显示的是“数据”,即最大值,以及同一张美国地图上的“类”类别。

谁能给我一些想法?非常感谢。

4

2 回答 2

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)

这给了我这个情节: 在此处输入图像描述

于 2013-08-05T18:11:20.763 回答
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))

从那里,您可以使用 jitter 和 alpha 来修复过度绘图。如果您首先将形状转换为一个因子,则可以将形状用作“类”的美学as.factor()

于 2013-08-05T18:07:03.760 回答