该包可画的图很多,也是 ggplot2 的扩展包,但对我最有用的还是题目中的两种(雷达图相关的地方也有用)。
当然绘制这两种图的方法很多,比如:
- gghalves,也可以分箱图,nice;
- 老俊俊在ggplot 绘制分半小提琴图+统计检验用到了 introdataviz 包的
geom_split_violin()
函数,他自己的包好像也有类似功能,参考jjPlot 绘制分半提琴和箱线图; - Split violin plot with ggplot2 ;
- ......
1. 分半小提琴图
要是有也截一半箱图的函数就更方便了。
-
geom_violinhalf()
flip
:TURE
时右,FALSE
时左。
df_iris <- iris %>% pivot_longer(-Species, names_to = "Type", values_to = "Length")
ggplot(df_iris) +
geom_violinhalf(data = filter(df_iris, Species == "virginica"),
aes(x = Type, y = Length, fill = Species), flip = T) +
geom_boxplot(data = filter(df_iris, Species == "virginica"),
aes(x = Type, y = Length),
width = 0.1,
position = position_nudge(x = -.05)) +
geom_violinhalf(data = filter(df_iris, Species == "versicolor"),
aes(x = Type, y = Length, fill = Species), flip = F) +
geom_boxplot(data = filter(df_iris, Species == "versicolor"),
aes(x = Type, y = Length),
width = 0.1,
position = position_nudge(x = .05)) +
scale_fill_manual(values = c("#e6550d", "#3182bd")) +
theme_bw()
分半小提琴图
2. 云雨图
-
geom_violindot()
dots_size
,dots_color
,dots_fill
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_violindot(dots_size = 2) +
scale_fill_manual(values = c("#FFCC00", "#009999", "#CC3333")) +
theme_bw()
云雨图
网友评论