美文网首页ggplot集锦
R | easystats 之 see:分半小提琴图、云雨图

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

作者: shwzhao | 来源:发表于2022-09-05 22:56 被阅读0次

    该包可画的图很多,也是 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()
    
    云雨图

    相关文章

      网友评论

        本文标题:R | easystats 之 see:分半小提琴图、云雨图

        本文链接:https://www.haomeiwen.com/subject/pyyunrtx.html