see包是一个R语言可视化工具包,它能为使用者提供漂亮的、出版级的图像展示。
本文中主要介绍see包使用的主要函数:
see包可以通过两种方式进行安装,一种是在gitlab进行安装,另一种是基于CRAN进行安装。
devtools::install_github("easystats/see") library(see)
install.packages("see")library(see)
p1 <- ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_boxplot() + theme_modern(axis.text.angle = 45) + scale_fill_material_d()
p2 <- ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_violin() + theme_modern(axis.text.angle = 45) + scale_fill_material_d(palette = "ice")
p3 <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Sepal.Length)) +
geom_point2() + theme_modern() + scale_color_material_c(palette = "rainbow")
plots(p1, p2, p3, n_columns = 2)
plots(p1, p2, p3, n_columns = 2, tags = paste("Fig. ", 1:3))
see包总共提供了modern、lucid、blackboard、abyss等四类主题。
library(ggplot2)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
geom_point2() + theme_modern()
library(ggplot2)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
geom_point2() + theme_lucid()
library(rstanarm)
library(modelbased)
dat <- rstanarm::stan_glm(Sepal.Width ~ poly(Petal.Length, 2),
data = iris) %>% estimate::estimate_link(keep_draws = TRUE,
length = 100, draws = 250) %>% estimate::reshape_draws()
p <- ggplot(dat, aes(x = Petal.Length, y = Draw, group = Draw_Group)) +
geom_line(color = "white", alpha = 0.05) + scale_x_continuous(expand = c(0,
0)) + scale_y_continuous(expand = c(0, 0))
p + theme_blackboard()
p1 <- ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_boxplot() + theme_modern(axis.text.angle = 45) + scale_fill_material_d()
p2 <- ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_violin() + theme_modern(axis.text.angle = 45) + scale_fill_material_d(palette = "ice")
p3 <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Sepal.Length)) +
geom_point2() + theme_modern() + scale_color_material_c(palette = "rainbow")
plots(p1, p2, p3, n_columns = 2)
see包提供geom_point2制作散点图, geom_point2允许散点无边界轮廓。
normal <- ggplot(iris, aes(x = Petal.Width, y = Sepal.Length)) +
geom_point(size = 8, alpha = 0.3) + theme_modern()
new <- ggplot(iris, aes(x = Petal.Width, y = Sepal.Length)) +
geom_point2(size = 8, alpha = 0.3) + theme_modern()
plots(normal, new, n_columns = 2)
image
library(dplyr)
library(tidyr)
data <- iris %>% group_by(Species) %>% summarise_all(mean) %>%
pivot_longer(-Species)
data %>% ggplot(aes(x = name, y = value, color = Species, group = Species)) +
geom_polygon(fill = NA, size = 2, show.legend = FALSE) +
coord_radar(start = -pi/4) + theme_minimal()
同时满足展示数据分布和数据多少的需求。
创建半小提琴半点图,可用于同时可视化分布和样本大小。
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_violindot(fill_dots = "black") + theme_modern() + scale_fill_material_d()