Use ggplot2
.
Something is missing in your example; the labels at the bottom do not match you data frame, and it's unclear how your sample dataframe would count up to values near 1000000. You might want to precompute/add a QC vector based on that to your dataframe; basically have your dataframe in a state that's ready to be plotted with minimal calculations.
Here's an example; I generate a dataframe with normally distributed values centered on 6.0 (seemed close to what your example had). I plot a dotted line at 6; and anything below 6 becomes red.
For the style, I directly took the function theme_Publication()
from this link.
Here's the code:
library("ggplot2")
# Themes for style
theme_Publication <- function(base_size=14, base_family="helvetica") { ... }
scale_fill_Publication <- function(...){ ... }
scale_colour_Publication <- function(...){ ... }
# Function to plot points as described
plotReads <-
function(DF) {
ggplot(DF) +
theme_Publication() + # Style it
geom_point(mapping = aes(x = as.factor(1:nrow(DF)), # Sequentially
y = log10_total_counts, # Y is the count values
color = QC)) + # Color it by the QC vector in the dataframe
scale_color_manual(values = c("PASS" = "black", "FAIL" = "red")) + # Tell it what colours to use.
geom_hline(yintercept = 6.0, linetype="dotted") + # Add the dotted line at 6.0
xlab("Sample") + # Label the X
ylab("log10(Total Reads)") + # Label the Y
ylim(c(-0.2, 8.2)) # Extend the Y axis to be between this range.
}
DF = data.frame(
log10_total_counts = rnorm(30, mean = 6, sd = 0.5), # Randomized data
QC = as.factor(c( rep("FAIL",15), rep("PASS", 15) )) # A vector that is just half FAIL and half PASS
)
plotReads(DF)
DF$QC <- as.factor(ifelse(DF$log10_total_counts < 6.0, "FAIL", "PASS")) # Now actually add some logic to what should be PASS or FAIL.
plotReads(DF)
None of the code uses anything from
gridExtra
- is it being loaded for code within the_Publication
functions?You're right, it's not needed here. Edited, and thanks!
Note: I cleaned up a discussion that sprang off an unwarranted comment of mine. Apologies!