我想在地图上绘制一些点。我试过这段代码:
lon <- c(103.25,103.28)
lat <- c(3.80, 3.78)
df <- as.data.frame(cbind(lon,lat))
获取地图
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 12,maptype = "satellite", scale = 3)
在地图上绘制一些点:
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8),size = 5, shape = 21) +guides(fill=FALSE, alpha=FALSE, size=FALSE)
根据此代码,会出现相同颜色的点。我的问题是,我想在地图上创建多种颜色的点。请帮忙,非常感谢您的帮助。谢谢。
答案 0 :(得分:2)
你需要添加一个分类变量(颜色应该表达什么?)来控制颜色美学:
#create some dummy data
df$coloringCategory <- rep(c("A","B"),length(df$lat)/2)
#in ggplot include the categorical variable
geom_point(data = df, aes(x = lon, y = lat, color= coloringCategory, alpha = 0.8),size = 5, shape = 21)