Reputation:
What I am looking to do, is generate 2 side by side boxplots that are separated by value. So essentially I have a data frame called exo. This table includes fields called mass_jupiter, (which is a table of 650 values 0.0001-10) orbital_period_days (which is a table with values 0.0001-7000 or something) and planet_name. I want to find out how to generate two side by side boxplots that compare the orbiting time of planets with masses greater than 1 to the orbiting time of planets with masses less than 1.
How would I go about this? I have tried > boxplot(exo"dollarsign"orbital_period_days ~ exo$mass_jupiter) but this just gave me 650 tiny boxplots for each different value for mass.
How would I group this into two side-by-side box plots for ones greater than 1 and less than 1?
Then I got frustrated and tried to create subsets of the data called largeexos and smallexos, where I broke all the data into two subsets. But I can't figure out a way to get both of those to boxplot next to each other either. Is there a way to do this as well?
Upvotes: 3
Views: 8495
Reputation: 8252
boxplot(orbital_period_days~mass_jupiter>1,exo)
should do that
Here's a small example data set (you should have provided one):
exo <- structure(list(mass_jupiter = c(0.996, 0.002, 0.827, 2.11, 0.008,
0.012, 0.2, 1.839, 0.008, 0.299, 0.322, 0.002, 9.904, 0.635,
0.088), orbital_period_days = c(3.443, 0.002, 1.657, 6749.824,
0.032, 0.007, 2.207, 1.495, 0.002, 0.574, 98.317, 0, 5.918, 24.229,
0.002)), .Names = c("mass_jupiter", "orbital_period_days"), row.names = c(NA,
-15L), class = "data.frame")
par(mfrow=c(1,2))
boxplot(orbital_period_days~mass_jupiter>1,exo,boxwex=.5)
boxplot(orbital_period_days~mass_jupiter>1,exo,boxwex=.5,log="y")
par(mfrow=c(1,1))
This produces:
The second axis is log-scaled (which considering your data may be wise)
Of course you'll want to set up titles, labels and so forth, but that's the basic idea.
Upvotes: 2