Created
September 24, 2012 19:35
-
-
Save wch/3777872 to your computer and use it in GitHub Desktop.
Examples for controls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Examples for controls | |
| ======================================================== | |
| ```{r tidy=FALSE, fig.width=4, fig.height=3 } | |
| library(ggplot2) | |
| # Base plot | |
| p <- ggplot(ToothGrowth, aes(x=factor(dose), y=len, fill=supp)) + | |
| scale_fill_manual(values=c("#E69F00", "#377EB8")) | |
| # Add control to change variable mapping, for example | |
| # ggplot(ToothGrowth, aes(x=supp, y=len, fill=factor(dose))) | |
| # ggplot(ToothGrowth, aes(x=supp, y=len)) | |
| # ggplot(ToothGrowth, aes(x=factor(dose), y=len)) | |
| # Add control to change colors | |
| # Point =============================== | |
| p + geom_point(shape=21) | |
| # Point: Add size control | |
| p + geom_point(shape=21, size=4) | |
| # Point: Add jitter control, and jitter width/height adjustment | |
| p + geom_point(shape=21, position=position_jitter(width=.15, height=0)) | |
| # Boxplot ============================= | |
| p + geom_boxplot() | |
| # Boxplot: Add width control | |
| p + geom_boxplot(width = .5) | |
| # Boxplot: Add notches (a little weird with this data set) | |
| p + geom_boxplot(notch = TRUE) | |
| # Violin ============================== | |
| p + geom_violin() | |
| # Violin: Add control for trim | |
| p + geom_violin(trim = FALSE) | |
| # Violin: Add control for bandwidth adjust (Default is 1) | |
| p + geom_violin(adjust=0.3) | |
| p + geom_violin(adjust=3) | |
| # Dot plot (in y direction) =========== | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="center") | |
| # Dot plot: Add control for stack direction | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="up") | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="center") | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="centerwhole") | |
| # Dot plot: Add control for bin algorithm | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", method="histodot") | |
| # Dot plot: Add control for bin width | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=0.75) | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=1) | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=1.5) | |
| p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=2) | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Published at http://rpubs.com/wch/1810