Reputation: 13
I have data in the form of this table. There are two conditions: Treated and Untreated.
Condition | ENSG | average raw counts |
---|---|---|
Untreated | ENSG00000260456 | 1.190091e-05 |
Treated | ENSG00000183570 | 2.935156e-05 |
I'm interested in making a box plot with the data in this format (i.e. red = treated, teal = untreated).
The code I have thus far makes a box plot by separating the x axis into bins, but I would like to have something that looks like the plot image above.
p <- joinSum %>%
mutate( bin=cut_width(`sumcol1`, width=0.00075, boundary=0) ) %>%
ggplot( aes(x=bin, y=joinSum$avg_rep) ) +
geom_boxplot(fill="#69b3a2") +
xlab("Bin")
print(p)
Here is an image of my current plot:
Upvotes: 1
Views: 72
Reputation: 26690
It was difficult to make a minimal reproducible example out of the data provided, but here is a potential solution:
library(tidyverse)
data <- tibble::tribble(
~Condition, ~ENSG, ~average.raw.counts,
"Untreated", "ENSG00000260456", 1.190091e-05,
"Treated", "ENSG00000183570", 1.195156e-05,
"Untreated", "ENSG00000260451", 1.290091e-05,
"Treated", "ENSG00000183572", 1.295156e-05,
"Untreated", "ENSG00000260454", 1.390091e-05,
"Treated", "ENSG00000183575", 1.395156e-05,
"Untreated", "ENSG00000260457", 1.110091e-05,
"Treated", "ENSG00000183578", 1.115156e-05
)
data %>%
mutate(bin = cut_width(average.raw.counts, width = 0.000002, boundary = 0)) %>%
ggplot(aes(x = bin, y = average.raw.counts)) +
geom_boxplot(aes(fill = Condition)) +
scale_fill_manual(values = c("#f60013", "#21fffe")) +
theme_minimal()
Upvotes: 1