我是R的新手,我试图解决问题寻找其他问题,但我不敢。我有一个问题,重叠我使用ggplot2和ggmap创建的不同热图。当单独绘制地图时,它可以工作。只有当我尝试将它们拼凑在一起时才会出现错误:
出现'fill'的比例已经存在。为“填充”添加另一个比例,它将取代现有比例。
这是我的代码:
us_map_g_str <- get_map(location = "detroit", zoom = 10)
ggmap(us_map_g_str, extent = "device") +
geom_density2d(data = data1,
aes(x=as.numeric(lon), y = as.numeric(lat)),
size = 0.3) +
stat_density2d(data = data1,
aes(x = as.numeric(lon), y = as.numeric(lat),
fill = ..level.., alpha = ..level..),
size = 0.3, bins = 500, geom = "polygon") +
scale_fill_gradient(low = "green", high = "red") +
scale_alpha(range = c(0, 0.3), guide = FALSE) +
geom_density2d(data = data2,
aes(x = as.numeric(lon), y = as.numeric(lat)),
size = 0.3) +
stat_density2d(data = data2,
aes(x = as.numeric(lon), y = as.numeric(lat),
fill = ..level.., alpha = ..level..),
size = 0.3, bins = 500, geom = "polygon") +
scale_fill_gradient(low = "blue", high = "black") +
scale_alpha(range = c(0, 0.3), guide = FALSE) +
geom_density2d(data = data3,
aes(x = as.numeric(lon), y = as.numeric(lat)),
size = 0.3) +
stat_density2d(data = data3,
aes(x = as.numeric(lon), y = as.numeric(lat),
fill = ..level.., alpha = ..level..),
size = 0.3, bins = 500, geom = "polygon") +
scale_fill_gradient(low = "yellow", high = "orange") +
scale_alpha(range = c(0, 0.3), guide = FALSE)
当我运行它时,他将最后一种颜色应用于每个热图,在这种情况下为黄橙色。
这就是我得到的: