Description Usage Arguments Details Value See Also Examples
Plot boxplots on the margins of a scatterplot in ggplot2. This code is not totally written by Ethan; he adapted it from http://www.r-bloggers.com/scatterplot-with-marginal-boxplots/.
1 2 |
data |
The data.frame to feed into ggplot2 |
x |
A character string of the x-values to use in 'data'. Will be coerced to numeric if it isn't already. |
y |
A character string of the y-values to use in 'data'. Will be coerced to numeric if it isn't already. |
by |
A character string of the factor to use in 'data' for color/fill. If missing, defaults to no grouping. Will be coerced to factor if it isn't already. |
xlim |
The x-limits. If missing, defaults to a good view. |
ylim |
The y-limits. If missing, defaults to a good view. |
xlab |
The x-label. Defaults to 'x'. See details. |
ylab |
The y-label. Defaults to 'y'. See details. |
bylab |
The label for the by-variable. Defaults to "". |
width |
The width of jitter. Default 0.1. A warning is issued if > 0.3. |
counts |
Display the counts of each 'by' group in the top right corner? If 'by' is missing, displays nrow(data). |
countsize |
If the counts are displayed, what size should they be? Default = 5 - floor(# levels / 4). |
I considered using arguments that don't require character strings, but I think this way might just be safer. The only downside is that I need to fill the xlab and ylab so they're not so dang ugly. That's why the defaults are to 'x' and 'y'. The plus-side is that I have fewer if-else's when specifying '+xlab()+ylab()' to 'ggplot()'. It's also easier (in my opinion) to catch when the variable names aren't in 'data'.
Nothing is returned; however, the ggplot objects are printed.
http://www.r-bloggers.com/scatterplot-with-marginal-boxplots/
1 2 3 | marginal.boxplot(pizza.data, x = "height", y = "time_to_fu")
marginal.boxplot(pizza.data, x = "height", y = "time_to_fu", by = "sex",
xlab = "Height", ylab = "Time to Follow-Up", bylab = "Sex", counts = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.