{see}:研究好物分享!能将统计模型画成图,还能拼接多个图片~
马上开始吧~
install.packages("see")
library(see)
# 先安装,后续会用到
install.packages("parameters")
install.packages("performance")
install.packages("effectsize")
install.packages("correlation")
install.packages("qqplotr") # 作图
install.packages("ggplot2") # 作图
# 数据1
data("ToothGrowth")
summary(ToothGrowth)

# 数据2
data("mtcars")
mtcars$am_factor <- factor(mtcars$am)
mtcars$cyl_factor <- factor(mtcars$cyl)
summary(mtcars)

library(parameters)
# 拟合模型
model <- lm(len ~ supp * dose, data = ToothGrowth)
# 作图
plot(parameters(model))

library(performance)
# 拟合模型
model1 <- lm(len ~ supp, data = ToothGrowth)
# 作图
plot(check_normality(model1), type = "qq")

library(correlation)
model3 <- correlation(mtcars[, c(1, 3:7)])
plot(summary(model3), show_data = "points")

library(ggplot2)
# 兼容ggplot2,修改x轴上标签
plot(parameters(model)) +
xlab("Coefficients")

ggplot(mtcars, aes(x = am_factor, y = mpg, fill = am_factor)) +
geom_violinhalf() +
theme_lucid() +
scale_fill_material_d()

ggplot(mtcars, aes(x = am_factor, y = mpg, fill = am_factor)) +
geom_violindot(size_dots = 6,
fill_dots = "grey") +
theme_lucid()

p1 <- ggplot(mtcars, aes(x = cyl_factor, y = mpg, fill = cyl_factor)) +
geom_boxplot() +
scale_fill_material(palette = "full")
p2 <- ggplot(mtcars, aes(x = cyl_factor, y = mpg, fill = cyl_factor)) +
geom_col(width = 0.5) +
scale_fill_material_d(palette = "ice")
p3 <- ggplot(mtcars, aes(x = mpg, y = disp, color = wt)) +
geom_point() +
scale_color_material_c(palette = "contrast")
# 拼接并排列多个图
plots(p1, p2, p3,
n_columns = 1)

plots(p1, p2, p3,
n_rows = 2,
title = "MTCARS",
tags = paste("Fig. ", LETTERS[1:3])
)

p <- ggplot(mtcars, aes(x = mpg, y = wt, color = am_factor)) +
geom_point() +
labs(color = "Transmission\n 0 = automatic\n 1 = manual")
p

p + theme_lucid()

p + theme_abyss()


[1]. https://easystats.github.io/see/
2024-05-27 09:48