
Geom_vline(aes(xintercept = mean(weight)), a <- ggplot(wdata, aes(x = weight))Ī + geom_histogram(bins = 30, color = "black", fill = "grey") + We can also arrange this as two plots with facet_wrap. What if we want to display our data subset by OJ vs Vitamin C? tg2 <- tg + geom_boxplot(aes(fill = supp), position = position_dodge(0.9)) + Scale_color_manual(values = c("indianred", "blue1", "green2")) We can also change boxplot colors by groups. Scale_x_discrete(limits = c("0.5", "2")) # Warning: Removed 20 rows containing missing values (stat_boxplot). We can also change the scale number of variables included, and their Stat_summary(fun.y = mean, geom = "point", shape = 18, size = 2.5, color = "indianred") # Warning: `fun.y` is deprecated. tg + geom_boxplot(notch = TRUE, fill = "lightgrey") +

Now lets look at a boxplot with points for the mean. tg <- ggplot(ToothGrowth, aes(x = dose, y = len)) Lets start with a very basic boxplot with dose vs length. Lets set the theme for our plots to classic. ToothGrowth$dose <- as.factor(ToothGrowth$dose) Lets change the dose to a factor, and look at the top of theĭataframe.

Scale_fill_manual(values = c("blue", "gold")) Scale_color_manual(values = c("blue", "gold")) + Geom_text(aes(y = lab_ypos, label = len, group = supp), color = "white") + Geom_col(aes(fill = supp), width = 0.7) + Mutate(lab_ypos = cumsum(len) - 0.5 * len) We’ll start with making a dataframe based on the tooth data.

Now lets take a look at some ggplot2 barplots.
