Examples for controls

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)

plot of chunk unnamed-chunk-1


# Point: Add size control
p + geom_point(shape=21, size=4)

plot of chunk unnamed-chunk-1


# Point: Add jitter control, and jitter width/height adjustment
p + geom_point(shape=21, position=position_jitter(width=.15, height=0))

plot of chunk unnamed-chunk-1




# Boxplot =============================
p + geom_boxplot()

plot of chunk unnamed-chunk-1


# Boxplot: Add width control
p + geom_boxplot(width = .5)

plot of chunk unnamed-chunk-1


# 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.

plot of chunk unnamed-chunk-1




# Violin ==============================
p + geom_violin()

plot of chunk unnamed-chunk-1


# Violin: Add control for trim
p + geom_violin(trim = FALSE)

plot of chunk unnamed-chunk-1


# Violin: Add control for bandwidth adjust (Default is 1)
p + geom_violin(adjust=0.3)

plot of chunk unnamed-chunk-1

p + geom_violin(adjust=3)

plot of chunk unnamed-chunk-1




# 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.

plot of chunk unnamed-chunk-1


# 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.

plot of chunk unnamed-chunk-1

p + geom_dotplot(binaxis="y", position="dodge", stackdir="center")
## stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.

plot of chunk unnamed-chunk-1

p + geom_dotplot(binaxis="y", position="dodge", stackdir="centerwhole")
## stat_bindot: binwidth defaulted to range/30. Use 'binwidth = x' to adjust
## this.

plot of chunk unnamed-chunk-1


# 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.

plot of chunk unnamed-chunk-1


# Dot plot: Add control for bin width
p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=0.75)

plot of chunk unnamed-chunk-1

p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=1)

plot of chunk unnamed-chunk-1

p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=1.5)

plot of chunk unnamed-chunk-1

p + geom_dotplot(binaxis="y", position="dodge", stackdir="center", binwidth=2)

plot of chunk unnamed-chunk-1