我使用ggmap
包,我想根据值绘制热图而不是记录数。
在其他关于相同主题的帖子的帮助下,我可以实现这个目标,但情节并不是真正的热图。
我确切地认为它不是Heatmap plot by value using ggmap和ggmap Heatmap with value的副本,因为我不想面对我的情节,也不想有一个等值线图。
以下是代码和数据摘录。
代码:
library(ggmap)
CentreCarte <- c(lon = 2.35, lat = 48.85)
Carte <- get_map(location = CentreCarte, source = "google", maptype = "terrain", zoom = 9, color = "bw")
ggmap(Carte) %+% MyData +
aes(x = lon, y = lat, z = Satisfaction) +
stat_summary2d(fun = median, alpha = 0.5)
数据:
structure(list(lon = c(2.336018, 2.336018, 2.5221629, 2.246237,
2.3259213, 2.16647, 2.1203554, 1.735384, 1.940096, 1.765638,
2.2899811, 2.165493, 2.110156, 2.378493, 2.3716529, 2.31002,
2.3827967, 2.3625879, 2.3529867, 2.3719424, 2.4270832, 2.897243,
2.656802, 2.6880829, 2.504403, 2.458625, 3.299203, 2.2785604),
lat = c(48.7022059, 48.7022059, 48.7708784, 48.589172, 48.6408416,
48.6792779, 48.8048649, 48.992181, 48.571308, 48.805027,
48.9162844, 48.990006, 48.880777, 48.997347, 49.093886, 48.796696,
48.8387005, 48.9259577, 48.891305, 48.8111854, 48.9156278,
48.928386, 48.7904005, 48.868659, 48.90852, 48.892489, 48.560149,
48.8399261), Satisfaction = c(5, 4, 1, 4, 3, 3, 2, 3, 5,
1, 4, 3, 1, 5, 3, 3, 3, 2, 3, 4, 2, 3, 3, 1, 2, 2, 5, 4)), .Names = c("lon",
"lat", "Satisfaction"), row.names = c(560L, 561L, 565L, 566L,
569L, 570L, 573L, 574L, 576L, 581L, 594L, 597L, 599L, 600L, 601L,
605L, 606L, 607L, 608L, 609L, 611L, 612L, 615L, 616L, 619L, 622L,
623L, 624L), class = "data.frame")
答案 0 :(得分:0)
您正在使用stat_summary2d()
,它将3D曲面绘制到2D矩形箱中。您发布的数据只有28个观测值。如果您想制作看起来像热图的东西,可以使用stat_density2d()
,它会根据您的数据估算密度。
ggmap(Carte) +
stat_density2d(data = MyData,
aes(x = lon, y = lat, fill = ..level.., alpha = ..level..),
geom = "polygon") +
scale_alpha(range = c(0, 1), guide = FALSE) +
scale_fill_gradient(low = "green", high = "red")