library(ggpubr)
演示数据集
数据:ToothGrowth 和 mtcars 数据集。
# ToothGrowth
data("ToothGrowth")
head(ToothGrowth)
# mtcars
data("mtcars")
mtcars$name <- rownames(mtcars)
mtcars$cyl <- as.factor(mtcars$cyl)
head(mtcars[, c("name", "wt", "mpg", "cyl")]
在这里,我们将使用GGPLOT2为基础绘制的可用功能ggpubr。您可以使用任何 ggplot2 函数来创建您想要稍后安排它们的图。
我们将首先创建 4 个不同的图:
使用ToothGrowth数据集的箱线图和点图
使用mtcars数据集的条形图和散点图
在接下来的部分中,您将学习如何使用特定函数组合这些图。
创建箱线图和点图:
# Box plot (bp)
bxp <- ggboxplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco")
bxp
# Dot plot (dp)
dp <- ggdotplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco", binwidth = 1)
dp