0

I have two objects, say a and b which are assigned to a variable in a data set (assume battery life of iphone (a) and samsung (b)) From what I know to draw the box plot for a, I simply write

boxplot(a)

And this is working, I get a perfectly good box plot for the respective data.

My question is how do I get both the box plots (for a and b) on one axis?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Bas
  • 1
  • Please provide a reproducible example if you require assistance. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Adam Quek Apr 13 '17 at 08:22
  • Not sure if this is the type of plot you are looking for... `boxplot(Sepal.Length ~ Species, data=iris)` – Adam Quek Apr 13 '17 at 08:23

1 Answers1

0

If you want to have more options for your plot, you can use ggplot2 library. Put "a" and "b" in a dataframe, reshape the dataframe (melt) and produce a lovely plot.

library(ggplot2)
library(reshape2)
df=data.frame(a,b)
df$id = row.names(df)
new = melt(df,id="id")
plot = ggplot(new)+geom_boxplot(aes(variable,value,fill=variable))
ggsave("boxplots.png",plot,width=200,height=200,unit="mm")

enter image description here

Beveline
  • 267
  • 3
  • 9