Loading libraries

library(tidyverse)
library(wesanderson)
library(scales)
library(patchwork)

Assigning and looking at structure of my data

I will focus on the Sepal.Length variable.

data <- iris
str(data)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...

Basic Box Plot of Sepal Length

ggplot(data) + aes(x=Sepal.Length,y=Species,fill=Species) +
  geom_boxplot()

Add formal title and axis labels to box plot

ggplot(data) + aes(x=Sepal.Length,y=Species,fill=Species) + geom_boxplot() + labs(title = "Boxplot", x = "Sepal Length (cm)", y="Plant Species") + theme(plot.title=element_text(hjust=0.5)) + theme(legend.position = "none")

Add points, change theme, and create final box plot

my_colors <- c(wes_palettes$GrandBudapest2)

p1 <- ggplot(data) + aes(x=Sepal.Length,y=Species,fill=Species) + geom_boxplot() + labs(title = "Boxplot", x = "Sepal Length (cm)", y="Plant Species") + theme(plot.title=element_text(hjust=0.5)) + geom_point(position=position_jitter(width=0.7,height=0.2),color="grey60",size=3) + theme(legend.position = "none") + scale_fill_manual(values = my_colors)

p1

Basic Density Plot of Sepal Length

ggplot(data) + aes(x=Sepal.Length,fill=Species) +
  geom_density()

Create final density plot

p2 <- ggplot(data) + aes(x=Sepal.Length,fill=Species) + geom_density() + labs(title = "Density Plot", x = "Sepal Length (cm)", y="Frequency") + theme(plot.title=element_text(hjust=0.5)) + scale_fill_manual(values = my_colors)

p2

Create final jitter plot

p3 <- ggplot(data) + aes(x=Species,y=Sepal.Length,color=Species) + geom_jitter() + labs(title = "Jitter Plot", x = "Plant Species", y="Sepal Length (cm)") + theme(plot.title=element_text(hjust=0.5))

p3

Combine all the plots into one final presentable plot

final_plot <- (p1|p2)/(p3)+plot_annotation(caption = "a. Boxplot of Sepal Length by Species
b. Density Plot of Sepal Length by Species
c. Jitter Plot of Sepal Length by Species", tag_levels = "a")

final_plot