R | easystats 之 see:分半小提琴图、云雨图

该包可画的图很多,也是 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()
云雨图
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容