2

Here's part of my data:

enter image description here

I would like to place box plots of "Maintain.Diverse..Functional", "Maintain.Focal.Rare", and "Restore.Habitat.Structure" side by side. I tried this:

boxplot(A$Maintain.Diverse..Functional, ylab="ranking", xlab="Maintain.Diverse..Functional")

But I only get one box plot, I was wondering how to add two other boxplots side by side with the same scale?!

data

structure(list(Maintain.Diverse..Functional = c(1, 1, 1, 2, 1, 
4, 4, 1, 4, 4, 7, 3, 6), Maintain.Focal.Rare = c(2, 3, 3, 4, 
2, 3, 1, 2, 1, 3, 2, 1, 1), Restore.Habitat.Structure = c(3, 
5, 2, 3, 3, 1, 2, 3, 2, 2, 6, NA, 3)), .Names = c("Maintain.Diverse..Functional", 
"Maintain.Focal.Rare", "Restore.Habitat.Structure"), row.names = c(NA, 
-13L), class = "data.frame")
user20650
  • 24,654
  • 5
  • 56
  • 91
munmunbb
  • 297
  • 9
  • 22
  • 2
    Please don't post data or code as screenshots. – zero323 Jul 24 '15 at 21:27
  • 3
    [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – zero323 Jul 24 '15 at 21:28
  • 1
    Hi Wendy, can you add the actual data as code please ... you can do this by editing your question with, for example, `dput(yourdata[1:10, 1:3])`, where `yourdata` is the name of the dataframe, and `1:3` gives the first three columns (change if needed). thanks – user20650 Jul 24 '15 at 21:29
  • 2
    Does `boxplot(yourdata[c("Maintain.Diverse..Functional", "Maintain.Focal.Rare", "Restore.Habitat.Structure" )])` do what you want? – user20650 Jul 24 '15 at 21:34
  • @user20650 yes it worked. Thanks a lot! – munmunbb Jul 25 '15 at 05:13

2 Answers2

2

It works when I typed this:

boxplot(yourdata[c("Maintain.Diverse..Functional", "Maintain.Focal.Rare", "Restore.Habitat.Structure" )])

Thank you @user20650 for your answer!

munmunbb
  • 297
  • 9
  • 22
1

You can create each box plot separately say box1, box2, box3.

With the gridExtra package, you can arrange them like:

grid.arrange(box1, box2, box3, ncol=3)