有此数据
Zip incidentType city state latitude longitude
1 00660 Flood Hormigueros PR 18.13911 -67.12085
2 00660 Severe Storm(s) Hormigueros PR 18.13911 -67.12085
3 00660 Severe Storm(s) Hormigueros PR 18.13911 -67.12085
4 00660 Flood Hormigueros PR 18.13911 -67.12085
5 00660 Flood Hormigueros PR 18.13911 -67.12085
6 01255 Flood Sandisfield MA 42.08897 -73.12444
并且我想绘制一个热图来绘制入射变量,该变量是以下代码中各个级别的一个因素
library(ggmap)
map <- get_map(location = "United States",zoom = 4,maptype = "terrain",
color = "color",source = "google")
ggmap(map,extent = "device") + geom_point(aes(x=latitude,y=longitude,
alpha=0.7,fill=incidentType,
col=incidentType),fun=sum,
data = dat1,na.rm = TRUE)
但是这些点未绘制在地图上。 请帮忙。
答案 0 :(得分:0)
存在多个问题。
zoom = 4
太小。请使用zoom = 3
。longitude
应该映射到x
。 latitude
应该映射到y
。ggplot
参数中指定base_layer
调用。 fun = sum
在这里是什么意思。alpha = 0.7
是aes
中的参数。这是固定代码。
dat <- read.table(text = "Zip incidentType city state latitude longitude
1 00660 Flood Hormigueros PR 18.13911 -67.12085
2 00660 'Severe Storm(s)' Hormigueros PR 18.13911 -67.12085
3 00660 'Severe Storm(s)' Hormigueros PR 18.13911 -67.12085
4 00660 Flood Hormigueros PR 18.13911 -67.12085
5 00660 Flood Hormigueros PR 18.13911 -67.12085
6 01255 Flood Sandisfield MA 42.08897 -73.12444",
header = TRUE, stringsAsFactors = FALSE)
library(ggmap)
map <- get_map(location = "United States",zoom = 3,maptype = "terrain",
color = "color",source = "google")
ggmap(map,
base_layer = ggplot(data = dat, aes(x = longitude, y = latitude))) +
geom_point(aes(fill = incidentType, col = incidentType), alpha = 0.7, size = 2)
这是情节。