Create a demo dataset to be used for a plot.
# Sample dataset
set.seed(3)
df <- data.frame(value = rexp(100),
group = sample(paste("Group", 1:5),
size = 100,
replace = TRUE)
)
head(df, 10)
## value group
## 1 1.73062657 Group 5
## 2 0.61503280 Group 5
## 3 1.23291659 Group 3
## 4 1.00408445 Group 4
## 5 0.20420135 Group 5
## 6 0.20878811 Group 4
## 7 2.28364334 Group 4
## 8 0.01004783 Group 1
## 9 0.06807071 Group 5
## 10 0.11449887 Group 4
A simple Box plot using R base function.
Vertical box plot with points
# Vertical box plot
boxplot(df$value, col = "white")
# Points
stripchart(df$value, # Data
method = "jitter", # Random noise
pch = 19, # Pch symbols
col = 4, # Color of the symbol
vertical = TRUE, # Vertical mode
add = TRUE # Add it over
)
Horizontal box plot with points.
# Horizontal box plot
boxplot(df$value, col = "white", horizontal = TRUE)
# Points
stripchart(df$value, # Data
method = "jitter", # Random noise
pch = 19, # Pch symbol
col = 4, # Color of the symbol
add = TRUE # Add it over
)
Vertical box plot by group with points
# Vertical box plot by group
boxplot(value ~ group, data = df, col = "white")
# Points
stripchart(value ~ group,
data = df,
method = "jitter",
pch = 19,
col = 2:6,
vertical = TRUE,
add = TRUE
)
grid()
Horizontal box plot by group with points
# Horizontal box plot by group
boxplot(value ~ group, data = df, col = "white",
horizontal = TRUE)
# Points
stripchart(value ~ group,
data = df,
method = "jitter",
pch = 19,
col = 2:6,
add = TRUE
)
grid()