簡體   English   中英

地圖上的多個點

[英]Multiple Points on Map

我想繪制一張地圖,上面有一些點。 我嘗試了這段代碼:

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)

根據此代碼,將顯示相同顏色的點。 我的問題是,我想在地圖上創建多種顏色的點。 請提供幫助,我們將不勝感激。 謝謝。

您需要添加類別變量(顏色應表示什么?)來控制顏色美觀度:

#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