代码之家  ›  专栏  ›  技术社区  ›  Workhorse

绘制ggplot2中数据的频率[重复]

  •  0
  • Workhorse  · 技术社区  · 7 年前

    这个问题已经有了答案:

    我有一个数据框架,如下所示:

    threshold <- c("thresh1","thresh3","thresh10","thresh3","thresh3", "thresh10")
    expression <- c("expressed", "expressed", "expressed", "depleted",  "expressed", "depleted")
    data.frame("Threshold" = threshold, "Expression" = expression)
    

    我想生成一个不同阈值计数的柱状图,用表达式括起来。

    我试图用 geom_bar() 但我不想把数据堆积起来。相反,我希望不同的类别(耗尽、丰富等)在它们自己的条形图中表示出来。

    ggplot(final_nonexpressed, aes(x = threshold, fill = expression))+geom_bar(width = 0.5)
    

    enter image description here

    任何帮助都将不胜感激!

    1 回复  |  直到 7 年前
        1
  •  0
  •   Chase    7 年前

    查看帮助页 ?geom_bar() 特别是 dodge 争论。例如:

    library(ggplot2)
    g <- ggplot(mpg, aes(class, fill = factor(drv)))
    g + geom_bar()
    

    g + geom_bar(position = "dodge")
    

    创建日期:2019-01-15 reprex package (v0.2.1)