RAG = “Red/Amber/Green”. This is a communication concept used in risk communication or decision making, correlating with traffic light colors.
This document is for demonstration of how to make a RAG plot using ggplot2 and grid. It is also for development of a high-throughput script for generating multiple publication-quality pdf charts from a properly-formatted data table.
This is the basic pipeline for the charts using a dummy data frame
assay.name <- c("assay1","assay2","assay3","assay4","assay5","assay6","assay7","assay8","assay9","assay10","assay11","assay12")
type <- c("A","A","B","A","A","B","C","D","D","E","D","C")
plot <- c("plot1","plot1","plot1","plot1","plot1","plot1","plot2","plot2","plot2","plot2","plot2","plot2")
copies.per.ml <- c(1e4,1e5,1e2,1e3,1e7,1e8,1e2,1e2,1e3,1e7,1e6,1e4)
test <- data.frame(assay.name,copies.per.ml,type,plot)
data <- test #remove this in the final product
testlibrary(ggplot2)
library(grid)
#creating the RAG background
g <- rasterGrob(c("green","#92ff14","#fff200","orange","red"), width=unit(1,"npc"), height = unit(1,"npc"),
interpolate = TRUE)
#brute-force creation of an all black color scale
manCol <- c("black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black","black")
#single plot
p <- ggplot(data, aes(x=type,y=copies.per.ml, color=assay.name))+
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
theme_classic()+
geom_jitter(size = 3,
position = position_dodge(width=0.5),
alpha = 1, show.legend = F)+
scale_color_manual(values = manCol)+
labs(x="Assays",y="gene copies per mL")+
scale_y_continuous(trans='log10', limits = c(1,1e8))
p
ggsave("test.pdf",device = "pdf", height = 5, width = 8)
ggsave("test.png",device = "png", height = 5, width = 8)
#looped plot; these will not display in RStudio but are saved properly
RAGcount <- unique(data$plot)
for (n in c(1:length(RAGcount))){
x <- subset(test, plot == RAGcount[n])
ggplot(x, aes(x=type,y=copies.per.ml, color=assay.name)) +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
theme_classic() +
geom_jitter(size = 3,
position = position_dodge(width=0.5),
alpha = 1, show.legend = F) +
scale_color_manual(values = manCol) +
labs(x="Assays",y="gene copies per mL") +
ggtitle(paste(RAGcount[n])) +
scale_y_continuous(trans='log10', limits = c(1,1e8))
x
ggsave(paste(RAGcount[n],".pdf",sep=""), device = "pdf", height = 5, width = 8)
ggsave(paste(RAGcount[n],".png",sep=""), device = "png", height = 5, width = 8)
}
#1e1 should be red
#1e4 yellow-green
#above transitions to greenThis script ends up producing 2 plots from the test data, one from each “plot” category variable in the data table.