-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadcount_barplot.R
More file actions
38 lines (32 loc) · 1.21 KB
/
readcount_barplot.R
File metadata and controls
38 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
##barplot to visualize sequencing results
# Load the data
data <- read_delim("~/Documents/Wrighton_lab/Agribiome/AG ML project/data processing/batch5_counts.csv")
library(dplyr)
library(ggplot2)
# 1. Assign fill color for plotting
data <- data %>%
mutate(
fill_color = case_when(
type == "target" ~ "grey",
type == "actual" & direction == "F" ~ "blue",
type == "actual" & direction == "R" ~ "red"
)
)
# 2. Create a new column that combines Sample and Type
# This is key to getting two bars per Sample
data <- data %>%
mutate(
sample_type = paste(Sample, type, sep = "_")
)
# 3. Plot with sample_type on x-axis so F/R stack within actual/target
ggplot(data, aes(x = sample_type, y = gbp, fill = fill_color)) +
geom_bar(stat = "identity") +
scale_fill_identity(guide = "legend",
labels = c("blue" = "Actual - F",
"red" = "Actual - R",
"grey" = "Target (F + R)"),
breaks = c("blue", "red", "grey"),
name = "Direction") +
labs(x = "Sample", y = "GBP", title = "Batch 5") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 9))