2017-02-11 28 views
0

我希望將4種顏色(紅色,藍色,綠色和黑色)與4種不同形狀(形狀編號15,16,17,19)組合在一起。這可能分配這些組合?我使用下面的代碼做了它,而顏色改變形狀沒有。ggplot2-scale_colour_manual和scale_shape手冊問題

這是代碼至今:

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

回答

0

您必須設置shape審美與scale_shape_manual使用。例如:

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')) 
+0

我所做的與您建議的模塊化方式相同。 – user2916044

+0

你確定嗎?你的例子設置了「填充」美學,而不是「形狀」?否則,我恐怕我沒有得到你的問題.. – Taeke

+0

即使我刪除填充它將無法正常工作。顏色改變形狀不。 – user2916044