0

I have a data frame that looks like the following:

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

I would like to generate a histogram of counts of the different thresholds, bucketed by the expression.

I have attempted to do so using geom_bar(), but I not want the data stacked. Rather, I want the different categories (depleted, enriched etc...) to be represented in their own bars.

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

enter image description here

Any help would be appreciated!

Workhorse
  • 1,500
  • 1
  • 17
  • 27

1 Answers1

0

Check out the help page for ?geom_bar(), specifically the dodge argument. For example:

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

g + geom_bar(position = "dodge")

Created on 2019-01-15 by the reprex package (v0.2.1)

Chase
  • 67,710
  • 18
  • 144
  • 161