【问题标题】:ggplot2-scale_colour_manual and scale_shape manual issueggplot2-scale_colour_manual 和 scale_shape 手动问题
【发布时间】:2017-02-11 21:39:56
【问题描述】:

我希望将 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" ))

【问题讨论】:

    标签: r ggplot2


    【解决方案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'))
    

    【讨论】:

    • 我所做的与您以模块化方式建议的相同。
    • 你确定吗?您的示例设置了 fill 美学,而不是 shape?否则,我恐怕我没有正确回答您的问题..
    • 即使我删除了填充,它也不起作用。颜色不会改变形状。
    • 您是否删除了填充添加了形状美学?您能否提供一个独立的示例,其中包含数据和所有内容,但未提供首选结果?
    猜你喜欢
    • 1970-01-01
    • 2012-09-02
    • 2010-12-01
    • 2020-02-04
    • 2018-09-10
    • 2015-06-02
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多