Create a side box in R or RStudio (grouped by value)
What I'm looking for is to generate 2 side by side that are separated by value. So I have a data frame called exo. This table includes fields called mass_jupiter (a table of 650 0.0001-10 values) orbital_period_days (which is a table with 0.0001-7000 values or whatever) and planet_name. I want to learn how to create two side by side that compare the orbital times of planets with masses greater than 1 to the orbital times of planets with masses less than 1.
How can i do this? I tried> boxplot (exo "dollarsign" orbital_period_days ~ exo $ mass_jupiter) but that only gave me 650 tiny boxes for each different mass value.
How would I group this into two side-by-side plots for units greater than 1 and less than 1?
Then I got frustrated and tried to create subsets of the data named largeexos and smallexos where I split all the data into two subsets. But I can't figure out how to get both of these boxes between each other. Is there a way to do this?
boxplot(orbital_period_days~mass_jupiter>1,exo)
gotta do it
Here's a small example of a dataset (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 gives:
The second axis is scaled to scale (which takes your data into account might be wise)
Of course, you will want to customize headers, labels, etc., but that's the basic idea.
source to share