ggplot集锦

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

2022-09-05  本文已影响0人  shwzhao

该包可画的图很多,也是 ggplot2 的扩展包,但对我最有用的还是题目中的两种(雷达图相关的地方也有用)。

当然绘制这两种图的方法很多,比如:

1. 分半小提琴图

要是有也截一半箱图的函数就更方便了。

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. 云雨图

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()
云雨图
上一篇 下一篇

猜你喜欢

热点阅读