Step
1: Make Sure All Packages are Loaded!
These
are the ones you need:
library(ggplot2)
library(dplyr)
Step
2: Read the Data & Name It!
This
reads in the data:
read.csv("Book1.csv")
Read
and store data in ‘df’:
df<-read.csv("Book1.csv") # df = data frame
If
you want to see the first few rows do:
head(df)
## TimeInDen DenningHabitat
## 1 163 Land
## 2 160 Land
## 3 157 Land
## 4 154 Land
## 5 154 Land
## 6 150 Land
Step
4: Seperation is Key!
If
table column has more than one ‘location’ within, then run to
seperate!
table(df$DenningHabitat)
##
## Land Landfast Ice Sea Ice
## 75 7 71
Step
5: Let’s Make the BOX PLOT!
ggplot(df, aes(x = DenningHabitat, y = TimeInDen, fill = DenningHabitat)) +
geom_jitter(aes(color = DenningHabitat), size = 1.2, alpha = 0.7, width = 0.15) +
coord_flip() +
geom_violin(trim = FALSE, scale = "width", alpha = 0.7) +
scale_fill_manual(values = c("Land" = "#FE8507",
"Landfast Ice" = "#9F4CF8",
"Sea Ice" = "#FA4684")) +
scale_color_manual(values = c("Land" = "#FE8507",
"Landfast Ice" = "#9F4CF8",
"Sea Ice" = "#FA4684")) +
labs(title = "The Amount of Time Bears Spend in \n Den by Habitat Type",
x = "Denning Habitat",
y = "Time in Den \n (days)",
fill = "Denning Habitat Type",
color = "Denning Habitat Type") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5, face = "bold"),
legend.position = "bottom",
legend.box.background = element_rect(color = "#000000", linewidth = 0.7),
legend.background = element_rect(fill = "#ffffff", color = NA))
