【问题标题】:Change shape and color of geom points in ggplot2更改 ggplot2 中几何点的形状和颜色
【发布时间】:2017-09-07 20:18:06
【问题描述】:

问题来了,下面的代码改变了数据点的颜色,但没有改变形状。怎么了?

g <- ggplot(mydata, aes(var1, var2)
g <- g + geom_point(aes(shape=var3, color=var3), shape=1)
g <- g + facet_grid(.~var4)
g <- g + theme(legend.position="bottom") + guides(colour = guide_legend(ncol = 1))

【问题讨论】:

  • 您有 2 次参数 shape 一次在 aes() 内,一次在外面。删除外面的一个...请在此处为任何问题提供可重现的示例。

标签: r ggplot2


【解决方案1】:

您的代码几乎是正确的。为什么你有两个shapes?
替换

geom_point(aes(shape=var3, color=var3), shape=1)

geom_point(aes(shape=var3, color=var3)

我就是这样写的:

library(ggplot2)
ggplot(mydata, aes(var1, var2) +
    geom_point(aes(shape = var3, color = var3)) +
    facet_grid(. ~ var4) +
    theme(legend.position = "bottom") + 
    guides(colour = guide_legend(ncol = 1))

【讨论】:

    猜你喜欢
    • 2022-09-27
    • 1970-01-01
    • 2015-11-13
    • 2010-11-26
    • 2022-11-27
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    相关资源
    最近更新 更多