
Last chance! 50% off unlimited learning
Sale ends in
Create a box plot with points. Box plots display a group of numerical data through their quartiles.
ggboxplot(data, x, y, combine = FALSE, merge = FALSE, color = "black",
fill = "white", palette = NULL, title = NULL, xlab = NULL,
ylab = NULL, facet.by = NULL, panel.labs = NULL,
short.panel.labs = TRUE, linetype = "solid", size = NULL, width = 0.7,
notch = FALSE, select = NULL, remove = NULL, order = NULL,
add = "none", add.params = list(), error.plot = "pointrange",
label = NULL, font.label = list(size = 11, color = "black"),
label.select = NULL, repel = FALSE, label.rectangle = FALSE,
ggtheme = theme_pubr(), ...)
Suggested values are one of c("dotplot", "jitter").
The plot can be easily customized using the function ggpar(). Read ?ggpar for changing:
main title and axis labels: main, xlab, ylab
axis limits: xlim, ylim (e.g.: ylim = c(0, 30))
axis scales: xscale, yscale (e.g.: yscale = "log2")
color palettes: palette = "Dark2" or palette = c("gray", "blue", "red")
legend title, labels and position: legend = "right"
plot orientation : orientation = c("vertical", "horizontal", "reverse")
ggpar
, ggviolin
, ggdotplot
and ggstripchart
.
# NOT RUN {
# Load data
data("ToothGrowth")
df <- ToothGrowth
# Basic plot
# +++++++++++++++++++++++++++
# width: change box plots width
ggboxplot(df, x = "dose", y = "len", width = 0.8)
# Change orientation: horizontal
ggboxplot(df, "dose", "len", orientation = "horizontal")
# Notched box plot
ggboxplot(df, x = "dose", y = "len",
notch = TRUE)
# Add dots
# ++++++++++++++++++++++++++
ggboxplot(df, x = "dose", y = "len",
add = "dotplot")
# Add jitter points and change the shape by groups
ggboxplot(df, x = "dose", y = "len",
add = "jitter", shape = "dose")
# Select and order items
# ++++++++++++++++++++++++++++++
# Select which items to display: "0.5" and "2"
ggboxplot(df, "dose", "len",
select = c("0.5", "2"))
# Change the default order of items
ggboxplot(df, "dose", "len",
order = c("2", "1", "0.5"))
# Change colors
# +++++++++++++++++++++++++++
# Change outline and fill colors
ggboxplot(df, "dose", "len",
color = "black", fill = "gray")
# Change outline colors by groups: dose
# Use custom color palette
# Add jitter points and change the shape by groups
ggboxplot(df, "dose", "len",
color = "dose", palette =c("#00AFBB", "#E7B800", "#FC4E07"),
add = "jitter", shape = "dose")
# Change fill color by groups: dose
ggboxplot(df, "dose", "len",
fill = "dose", palette = c("#00AFBB", "#E7B800", "#FC4E07"))
# Box plot with multiple groups
# +++++++++++++++++++++
# fill or color box plot by a second group : "supp"
ggboxplot(df, "dose", "len", color = "supp",
palette = c("#00AFBB", "#E7B800"))
# }
Run the code above in your browser using DataLab