簡體   English   中英

R中的幾何點可視化問題

[英]Geom point visualization issue in R

這是與上一個問題相關聯的問題(調整ggplot2中的legend.title,legend.text和legend顏色)。 我在更改圖中的幾何點(跑步和步行分割)的顏色時遇到問題。 有人可以幫我嗎? 還有其他方法可以使我獲得更好的細分效果嗎? 謝謝

  er<-  ggmap(sq_map2) + 
  geom_point(data = sisquoc, size = 8,  aes(fill = Segmentation)) +  
  geom_line(data = sisquoc, size = 3,  aes(color =SpeedMeterPerSecond)) +
  geom_text(data = sisquoc, aes(label = paste("  ", 
                                             as.character(Location_ids), 
  sep="")), 
           angle = 60, hjust = 0, color = "sienna4",size = 6 ) 

   gg<- er  +   labs(x ="Longitude", y = "Latitude") +
   theme(axis.title = element_text(size=20), 
       panel.background = element_rect(fill = "white",size = 0.5, linetype = 
                                         "dotted"),
       panel.grid.major = element_line(size = 0.5, linetype = 
   'dotted',colour 
                                       = "black"), 
       panel.grid.minor = element_line(size = 0.5, linetype = 
   'dotted',colour 
                                       = "black"),
       panel.border = element_rect(colour = "black", fill=NA, size=0.5),
       axis.text.y   = element_text(size=18),
       axis.text.x   = element_text(size=18))

    gg  + theme(legend.position="right", 
           legend.title = element_text(colour="Black", size=18),
           legend.text = element_text(colour="black", size = 15),
           legend.background = element_rect(fill="grey90",
                                            size=0.5, linetype="solid", 
                                            colour ="black"))  + 
    scale_color_continuous(name="Speed (m/s)\n")

我假設您要更改圖中點的顏色。 試試+ scale_fill_manual(values = c("Run" = "black","Walk" = "grey"))

為了使geom_point使用aes(fill=...)您必須選擇除顏色值外還可以采用填充值的形狀,否則geom_point需要aes(colour=...) 填充是在此處使用的適當的aes ,因為您已經在geom_line使用了aes(colour=...)

在此處查看采用填充值的可能形狀21至25

嘗試:

ggmap(sq_map2) + 
  geom_point(data = sisquoc, size = 8,  aes(fill = Segmentation, shape = Segmentation) +
  scale_shape_manual(values=c(21, 24))

您可以使用例如scale_fill_manual(values=c("red", "blue"))進一步定義填充值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM