How to Make Boxplots in R

Channel:
Subscribers:
53,300
Published on ● Video Link: https://www.youtube.com/watch?v=8h_ms3ElCrg



Category:
Tutorial
Duration: 2:54
2,657 views
24


Boxplots provide a visual representation of the distribution of numeric variables that include key values such as the median, 25th and 75th percentiles. Side-by-side boxplots let you break plots out by a second categorical variable to compare differences across groups.

#Rprogramming #Datavizualization #ggplot2

Code used in this clip:

library(tidyverse)

data <- diamonds
colors <- c("#FFFFFF","#F5FCC2","#E0ED87","#CCDE57",
"#B3C732","#94A813","#718200")

# Boxplot in base R
boxplot(data$price)

# Boxplot in ggplot2
data %>% ggplot(aes(y = price)) +
geom_boxplot() +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank())

# Side-by-side boxplots in base R
boxplot(data$price ~ data$color)

# Side-by-side boxplots in ggplot2
data %>% ggplot(aes(x = color, y = price, fill = color)) +
geom_boxplot() +
scale_fill_manual(values = colors)



Code Clips are basic code explanations in 3 minutes or less. They are intended to be short reference guides that provide quick breakdowns and copy/paste access to code needed to accomplish common data science tasks. Think Stack Overflow with a video explanation.


* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above may not be exactly the same as the code shown in the video! For R that means I may use = for assignment and the special Unicode large < and > symbols in place of the standard sized ones for dplyr pipes and comparisons. These special symbols should work as expected for R code on Windows, but may need to be replaced with standard greater than and less than symbols for other operating systems.







Tags:
boxplot in r
boxplot in ggplot2
r boxplots
ggplot2 boxplot
side by side boxplot in r
side by side boxplot ggplot2
r plotting tutorial
boxplot
box plot in r
how to make a boxplot in r
how to make a box plot in r
ggplot boxplots
box
plot
ggplot boxplot
make boxplots in r
make box plots in r
make boxplots in ggplot
make boxplots in ggplot2