zoukankan      html  css  js  c++  java
  • R语言与医学统计图形-【13】ggplot2几何对象之盒形图

    ggplot2绘图系统——几何对象之盒形图

    参数:

    geom_boxplot(mapping = ,
                 #lower,middle,upper,x,ymax,ymin必须(有默认)
                 #alpha/color/fill/linetype/shape/size/weight可选
                 data = ,
                 stat = 'boxplot',
                 position = 'dodge',
                 outlier.color = , #离群点颜色
                 outlier.shape = 19,
                 outlier.size = 1.5,
                 outlier.stroke = 0.5,
                 notch = FALSE, #是否加卡槽
                 notchwidth = 0.5,
                 varwidth = FALSE, #盒子宽度是否随数目变化
                 na.rm = FALSE,
                 show.legend = ,
                 inherit.aes = TRUE
                 )
    

    示例。

    p <- ggplot(mpg,aes(class,hwy))
    p+geom_boxplot()
    
    #添加散点
    p+geom_boxplot()+geom_point(color='red')
    

    image.png

    #增加扰动
    p+geom_boxplot(outlier.color = 'white')+ 
      geom_jitter(width = 0.2,alpha=0.5,color='orange')
    
    #让离群点消失
    p+geom_boxplot(outlier.alpha = 0)+ 
      geom_jitter(width = 0.2,alpha=0.5,color='orange')
    

    image.png
    卡槽设置。

    #卡槽
    p <- ggplot(mpg,aes(class,hwy))
    p+geom_boxplot(notch = T)
    #卡槽超出了盒子边缘
    
    #宽度
    p+geom_boxplot(varwidth = T)
    

    image.png

    颜色设置。

    #颜色
    p+geom_boxplot(fill='forestgreen',color='black')
    
    #映射变量
    p+geom_boxplot(aes(color=drv))
    

    image.png

  • 相关阅读:
    Rock the Tech Interview
    k-d Tree in TripAdvisor
    Randomized QuickSelect
    Kth Smallest Element in Unsorted Array
    Quick Sort
    LRU Cache 解答
    Implement Queue using Stacks 解答
    Implement Stack using Queues 解答
    ListNode Review ReverseListNode
    BackTracking
  • 原文地址:https://www.cnblogs.com/jessepeng/p/12307733.html
Copyright © 2011-2022 走看看