ggmap-统计和比例填充梯度限值
我使用ggmap和stat_binhex来可视化给定区域内船只的密度。我不想显示所有的位置,只想显示那些我确实拥有高密度位置的位置 所以我使用“scale\u fill\u gradientn”和limits参数来过滤所有小于500个位置的六边形。limit参数需要指定最低值和最高值。虽然对于最低的值没有问题,但我不想手动指定最高的值(目前为100000),而是从“stat_binhex”结果中获取它。你知道这是否可能,我怎么能做到 这是我目前的代码:ggmap-统计和比例填充梯度限值,ggmap,Ggmap,我使用ggmap和stat_binhex来可视化给定区域内船只的密度。我不想显示所有的位置,只想显示那些我确实拥有高密度位置的位置 所以我使用“scale\u fill\u gradientn”和limits参数来过滤所有小于500个位置的六边形。limit参数需要指定最低值和最高值。虽然对于最低的值没有问题,但我不想手动指定最高的值(目前为100000),而是从“stat_binhex”结果中获取它。你知道这是否可能,我怎么能做到 这是我目前的代码: ggmap(map, extent =
ggmap(map, extent = "panel", maprange=FALSE) +
coord_cartesian() +
theme(legend.position='none') +
geom_point(data=positions, aes(x=positions$x, y=positions$y), alpha=0.1, size=0.01, color="grey") +
stat_binhex(data=positions, aes(x,y), binwidth=c(0.05, 0.05)) +
scale_fill_gradientn( colours= brewer.pal( 6, "YlGn"),
na.value = NA, trans= "log10", limits=c(500,100000))
谢谢你的帮助
Arnaud帮助页面
“缩放填充”梯度n
指向“连续缩放”
,表示您可以使用NA
(或NA\u real\u
)来设置您不想手动设置的限制。使用虚拟数据集:
以下是完整的代码:
library(ggmap)
library(RColorBrewer)
left <- -4.8
bottom <- 45.8
right <- -1.2
top <- 48.2
map <- get_stamenmap(c(left, bottom, right, top),
maptype = "toner", zoom = 8)
positions <- data.frame(x = rnorm(5e5, mean = -4, sd = 0.5),
y = rnorm(5e5, mean = 46.5, sd = 0.3))
positions <- positions[with(positions, x > left & x < right &
y > bottom & y < top), ]
print(ggmap(map, extent = "panel", maprange=FALSE) +
coord_cartesian() +
theme(legend.position="none") +
geom_point(data=positions, aes(x, y), alpha=0.1, size=0.01,
color="grey") +
stat_binhex(data=positions, aes(x, y), binwidth=c(0.05, 0.05)) +
scale_fill_gradientn(colours = brewer.pal( 6, "YlGn"),
na.value = NA, trans= "log10", limits = c(500, NA)))
库(ggmap)
图书馆(RColorBrewer)
左图:您能否提供最小的数据集?