ggplot2中数据的绘图频率

时间:2019-01-16 03:55:10

标签: r dataframe ggplot2

我有一个如下数据框:

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 个答案:

答案 0 :(得分:0)

请查看?geom_bar()(特别是dodge参数)的帮助页面。例如:

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

g + geom_bar(position = "dodge")

reprex package(v0.2.1)于2019-01-15创建

相关问题