Question
I am trying to figure out how to plot boxplots and a together in one graph.
Starting with the following:
data <- data.frame(matrix(rexp(50), 50))
colnames(data)[1] <- c("values")
data$s1 <- as.factor(c(rep("AA", 30), rep("AC", 18), rep("CC", 2)))
data$s2 <- as.factor(c(rep("AA", 25), rep("AG", 22), rep("GG", 3)))
boxplot(as.numeric(values)~s1,data=data, outline=F, range=1.5)
boxplot(as.numeric(values)~s2,data=data, outline=F, range=1.5)
I nearly get what I want. But since the numbers for the CC and GG group are small, I was adviced to plot only the 2 or 3 dots for the CC and GG group respectively.
Or maybe would it be better to do a simple chartplot using the previous data? How would this be done?
Solution
Is this what you are looking for?
par(mfrow=c(1, 2))
boxplot(as.numeric(values) ~ s1,
data=subset(data, data$s1=="AA" | data$s1=="AC"))
stripchart(as.numeric(values) ~ s1,
data=data, add=TRUE, vertical=TRUE, pch=1, lwd=1)
boxplot(as.numeric(values) ~ s2,
data=subset(data, data$s1=="AA" | data$s1=="AG"))
stripchart(as.numeric(values) ~ s2,
data=data, add=TRUE, vertical=TRUE, pch=1, lwd=1)
Giving something like this:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow