我希望将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" ))
答案 0 :(得分:1)
您必须将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'))