我正在尝试将点绘制到ggmap对象上。我希望能够为数据框中的每个点(在data$col
下面)指定颜色。在下面的最小工作示例中,两个点应为红色,两个点应为绿色,两个点应为蓝色。但是,在最终图中,蓝色映射为红色,绿色映射为红色,红色映射为蓝色。关于如何将点正确映射到data变量中指定的这些颜色的任何想法,将不胜感激!
library(ggmap)
library(ggplot2)
lat = c(38.4123, 38.4139, 38.3997, 38.3941, 38.3949, 38.3950)
lon = c(-110.7835, -110.7819, -110.7916, -110.7896, -110.7869, -110.7852)
data = data.frame(lon=lon, lat=lat)
data$size <- c(1,3,5,7,10,10)
data$color <- c("red", "red", "blue", "blue", "green", "green")
bbox <- ggmap::make_bbox(lon=lon, lat=lat, data, f = 0.05)
mapLoc <- get_map(location = bbox, zoom = 13, maptype = "satellite")
col <- as.character(data$color)
p <- ggmap(mapLoc, extent = "panel", legend = "bottomright") +
geom_point(aes(x = lon, y = lat, size = size, color = factor(color)),
data = data) +
scale_color_manual(values=col)