简体   繁体   English

地图上的多个点

[英]Multiple Points on Map

I want to plot a map with some points on it. 我想绘制一张地图,上面有一些点。 I tried this code: 我尝试了这段代码:

lon <- c(103.25,103.28)
lat <- c(3.80, 3.78)
df <- as.data.frame(cbind(lon,lat))

Getting the map: 获取地图:

mapgilbert <- get_map(location = c(lon = mean(df$lon), lat =  mean(df$lat)), zoom = 12,maptype = "satellite", scale = 3)

Plotting the map with some points on it: 在地图上绘制一些点:

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)

Based on this code, the same color of points appear. 根据此代码,将显示相同颜色的点。 My question is, I want to create multiple color of points on the map. 我的问题是,我想在地图上创建多种颜色的点。 Kindly assist, your help is highly appreciated. 请提供帮助,我们将不胜感激。 Thank you. 谢谢。

You need to add a categorical variable (what should the colors express?) to govern the color aesthetics: 您需要添加类别变量(颜色应表示什么?)来控制颜色美观度:

#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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM