我希望将 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'))
关于r - ggplot2-scale_colour_manual和scale_shape手动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42176203/