简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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