简体   繁体   中英

Boxplot of 2 groups in R with graphics::boxplot

I have 2 groups of data (top and bottom) that I have been able to make boxplots for separately, but cannot get them to show in the same graph. I want them side by side for comparison for each gene tested (12 total). So, I would like to have the x-axis labeled with the gene tested, and the y-axis with the ddCt values, with 2 boxplots (1 for the top, 1 for the bottom) for each gene. I have the code for each one separately that works below:

# boxplot of first group
boxplot(Top25[-1], main = "Top Performers Gene Expression Relative to 16S", ylab = "ddCt Values", xlab = "Biofilm Gene", cex.axis = 0.75)

# boxplot of second group 
boxplot(Bottom25 [-1], main = "Bottom Performers Biofilm Gene Expression Relative to 16S", ylab = "ddCt Values", xlab = "Biofilm Gene", cex.axis = 0.75)

Any suggestions for what I may try? I've tried to "melt" them together following another ggplot2 question and got an error saying "object melt was not found". Thanks for any help!

Here is an example. The main idea is to use add = TRUE to add boxplot to an existing plot and specify the horizontal position of boxplot with at

#DATA
set.seed(42)
top = rnorm(40)
bottom = rnorm(40)

#Create Empty Plot
plot(1, 1, type = "n", xlim = c(0, 3), ylim = range(c(top, bottom)),
     ann = FALSE, xaxt = "n")

#Add boxplots to existing plot
boxplot(x = top, at = 1, add = TRUE)
boxplot(x = bottom, at = 2, add = TRUE)
axis(1, at = c(1, 2), labels = c("top", "bottom"))

在此处输入图片说明

You can do this:

Top25 <- data.frame(gene=1:40, exp=rnorm(40, 2))
Bottom25 <- data.frame(gene=41:80, exp=rnorm(40, -2))

boxplot(list(Top25[, -1], Bottom25[, -1]), names=c("Top25", "Bottom25"))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM