簡體   English   中英

ggplot2-scale_colour_manual 和 scale_shape 手動問題

[英]ggplot2-scale_colour_manual and scale_shape manual issue

我希望將 4 種顏色(紅色、藍色、綠色和黑色)與 4 種不同的形狀(形狀編號 15、16、17、19)結合起來。 這可以分配這些組合嗎? 我使用下面的代碼完成了它,雖然顏色改變了形狀,但形狀沒有改變。

這是到目前為止的代碼:

Lplot<- ggplot(totdt, aes(x=X1, y=Y2, color = Sp, fill=Sp)) + geom_polygon(data=zone2, alpha=.1)  + geom_point(size = 3)  
Lplot<- Lplot+ scale_shape_manual(values=c(15,16,17,19, 15,16,17,19, 15,16,17,19, 15,16,17,19 ))
Lplot<- Lplot+ scale_colour_manual(values = c("red", "blue", "green", "black","red", "blue", "green", "black","red", "blue", "green", "black","red", "blue", "green", "black","red" ))

您必須設置要與scale_shape_manual一起使用的shape美學。 例如:

data('"mtcars"')
cars <- mtcars %>% group_by(gear, cyl = as.factor(cyl)) %>% summarise(n = n())

ggplot(cars, aes(x = gear, y = n)) +
    geom_line(aes(color = cyl)) + geom_point(aes(shape = cyl)) +
    scale_shape_manual(values = c(15, 16, 17)) +
    scale_color_manual(values = c('red', 'blue', 'green'))

暫無
暫無

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

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