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)
## Warning: notch went outside hinges. Try setting notch=FALSE.
## Warning: notch went outside hinges. Try setting notch=FALSE.
## Warning: notch went outside hinges. Try setting notch=FALSE.
## Warning: notch went outside hinges. Try setting notch=FALSE.
## Warning: notch went outside hinges. Try setting notch=FALSE.
## Warning: notch went outside hinges. Try setting notch=FALSE.
# 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")
## stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.
# Dot plot: Add control for stack direction
p + geom_dotplot(binaxis="y", position="dodge", stackdir="up")
## stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.
p + geom_dotplot(binaxis="y", position="dodge", stackdir="center")
## stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.
p + geom_dotplot(binaxis="y", position="dodge", stackdir="centerwhole")
## stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.
# Dot plot: Add control for bin algorithm
p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", method="histodot")
## stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.
# 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)