无法使用ggmap设置大小
Unable to set size with ggmap
在我的例子中,我正在努力根据参数值 "clicks" 设置点的大小,理想的大小命令应该有效,但它对我不起作用 somehow.Its 抛出错误 错误:集合美学的不兼容长度:大小
这是我的努力:
library(ggmap)
library(ggplot2)
map <- get_googlemap(center = c(lon = -73.99, lat = 40.75), color = "bw", scale = 2,zoom=12)
x <- ggmap(map,extent = "device") +geom_point(aes(longitude.x, latitude.x,colour=factor(geo_region)),
data=data_ny, na.rm=T,size=3)+ scale_size_continuous(range =range(data_ny$clicks))
x
DPUT 是:
structure(list(geo_region = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "NY", class = "factor"),
io_id = c(262046L, 262045L, 262048L, 262046L, 262048L, 262048L,
262045L, 262046L, 262046L, 262048L, 262048L, 262046L, 262046L,
262048L, 262048L, 262046L, 262046L, 262048L, 262046L, 262048L,
262045L, 262046L, 262048L, 262045L, 262048L, 262045L, 262046L,
262048L, 262045L, 262046L, 262045L, 262048L, 262046L, 262048L,
262045L, 262046L, 262048L, 262045L, 262046L, 262046L, 262045L,
262048L, 262046L, 262045L, 262048L, 262045L, 262048L, 262046L,
262046L, 262048L), city.x = c("new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york"), latitude.x = c(40.75, 40.75, 40.75,
40.72, 40.72, 40.73, 40.73, 40.73, 40.7, 40.7, 40.71, 40.71,
40.71, 40.71, 40.71, 40.71, 40.71, 40.71, 40.72, 40.72, 40.72,
40.74, 40.74, 40.74, 40.74, 40.74, 40.74, 40.72, 40.72, 40.72,
40.72, 40.72, 40.72, 40.73, 40.73, 40.73, 40.75, 40.75, 40.75,
40.75, 40.75, 40.75, 40.76, 40.76, 40.76, 40.76, 40.76, 40.76,
40.76, 40.76), longitude.x = c(-73.99, -73.99, -73.99, -73.99,
-73.99, -73.99, -73.99, -73.99, -74.01, -74.01, -74.01, -74.01,
-74.01, -74.01, -74.01, -74.01, -74.01, -74.01, -73.98, -73.98,
-73.98, -73.99, -73.99, -73.99, -74, -74, -74, -74, -74,
-74, -74, -74, -74, -74.01, -74.01, -74.01, -73.98, -73.98,
-73.98, -73.97, -73.97, -73.97, -73.99, -73.99, -73.99, -73.99,
-73.99, -73.99, -73.98, -73.98), clicks = c(30L, 0L, 9L,
12L, 3L, 15L, 0L, 30L, 3L, 4L, 4L, 22L, 2L, 0L, 4L, 3L, 0L,
0L, 15L, 14L, 0L, 10L, 3L, 0L, 24L, 0L, 44L, 9L, 0L, 11L,
0L, 11L, 11L, 8L, 0L, 11L, 20L, 0L, 49L, 24L, 0L, 12L, 13L,
0L, 15L, 0L, 14L, 30L, 4L, 4L)), .Names = c("geo_region",
"io_id", "city.x", "latitude.x", "longitude.x", "clicks"), row.names = c(NA,
50L), class = "data.frame")
这是我固定 Size = 4 时得到的示例输出
但我希望尺寸根据点击次数动态变化。理想情况下 size=data_ny$clicks 应该可以,但不行,谁能帮我解决这个小问题。
您的名称有误,我认为添加 alpha(透明度)规范将有助于解决几乎相邻的重叠点具有不同点击次数的问题:
x <- ggmap(map,extent = "device") +
geom_point(data=data_ny, aes(x=longitude.x, y=latitude.x),
color="blue", alpha=0.3,
size=na.omit(data_ny$clicks), na.rm=TRUE ) +
scale_size_continuous(range =range(data_ny$clicks))
png(); print(x); dev.off()
在我的例子中,我正在努力根据参数值 "clicks" 设置点的大小,理想的大小命令应该有效,但它对我不起作用 somehow.Its 抛出错误 错误:集合美学的不兼容长度:大小 这是我的努力:
library(ggmap)
library(ggplot2)
map <- get_googlemap(center = c(lon = -73.99, lat = 40.75), color = "bw", scale = 2,zoom=12)
x <- ggmap(map,extent = "device") +geom_point(aes(longitude.x, latitude.x,colour=factor(geo_region)),
data=data_ny, na.rm=T,size=3)+ scale_size_continuous(range =range(data_ny$clicks))
x
DPUT 是:
structure(list(geo_region = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "NY", class = "factor"),
io_id = c(262046L, 262045L, 262048L, 262046L, 262048L, 262048L,
262045L, 262046L, 262046L, 262048L, 262048L, 262046L, 262046L,
262048L, 262048L, 262046L, 262046L, 262048L, 262046L, 262048L,
262045L, 262046L, 262048L, 262045L, 262048L, 262045L, 262046L,
262048L, 262045L, 262046L, 262045L, 262048L, 262046L, 262048L,
262045L, 262046L, 262048L, 262045L, 262046L, 262046L, 262045L,
262048L, 262046L, 262045L, 262048L, 262045L, 262048L, 262046L,
262046L, 262048L), city.x = c("new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york", "new york", "new york", "new york",
"new york", "new york"), latitude.x = c(40.75, 40.75, 40.75,
40.72, 40.72, 40.73, 40.73, 40.73, 40.7, 40.7, 40.71, 40.71,
40.71, 40.71, 40.71, 40.71, 40.71, 40.71, 40.72, 40.72, 40.72,
40.74, 40.74, 40.74, 40.74, 40.74, 40.74, 40.72, 40.72, 40.72,
40.72, 40.72, 40.72, 40.73, 40.73, 40.73, 40.75, 40.75, 40.75,
40.75, 40.75, 40.75, 40.76, 40.76, 40.76, 40.76, 40.76, 40.76,
40.76, 40.76), longitude.x = c(-73.99, -73.99, -73.99, -73.99,
-73.99, -73.99, -73.99, -73.99, -74.01, -74.01, -74.01, -74.01,
-74.01, -74.01, -74.01, -74.01, -74.01, -74.01, -73.98, -73.98,
-73.98, -73.99, -73.99, -73.99, -74, -74, -74, -74, -74,
-74, -74, -74, -74, -74.01, -74.01, -74.01, -73.98, -73.98,
-73.98, -73.97, -73.97, -73.97, -73.99, -73.99, -73.99, -73.99,
-73.99, -73.99, -73.98, -73.98), clicks = c(30L, 0L, 9L,
12L, 3L, 15L, 0L, 30L, 3L, 4L, 4L, 22L, 2L, 0L, 4L, 3L, 0L,
0L, 15L, 14L, 0L, 10L, 3L, 0L, 24L, 0L, 44L, 9L, 0L, 11L,
0L, 11L, 11L, 8L, 0L, 11L, 20L, 0L, 49L, 24L, 0L, 12L, 13L,
0L, 15L, 0L, 14L, 30L, 4L, 4L)), .Names = c("geo_region",
"io_id", "city.x", "latitude.x", "longitude.x", "clicks"), row.names = c(NA,
50L), class = "data.frame")
这是我固定 Size = 4 时得到的示例输出
但我希望尺寸根据点击次数动态变化。理想情况下 size=data_ny$clicks 应该可以,但不行,谁能帮我解决这个小问题。
您的名称有误,我认为添加 alpha(透明度)规范将有助于解决几乎相邻的重叠点具有不同点击次数的问题:
x <- ggmap(map,extent = "device") +
geom_point(data=data_ny, aes(x=longitude.x, y=latitude.x),
color="blue", alpha=0.3,
size=na.omit(data_ny$clicks), na.rm=TRUE ) +
scale_size_continuous(range =range(data_ny$clicks))
png(); print(x); dev.off()