Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 不同的分位数:箱线图与紫线图_R_Ggplot2_Boxplot_Quantile_Violin Plot - Fatal编程技术网

R 不同的分位数:箱线图与紫线图

R 不同的分位数:箱线图与紫线图,r,ggplot2,boxplot,quantile,violin-plot,R,Ggplot2,Boxplot,Quantile,Violin Plot,据我所知,方框图中的方框末端分别表示25%和75%的分位数,中间值=50%。因此,它们应该等于draw_quantiles=c(0.25,0.5,0.75)参数中由geom_小提琴绘制的0.25/0.5/0.75分位数 中位数和50%分位数拟合。然而,0.25和0.75分位数都不适合箱线图的箱端(见图,尤其是“virginica”面) 参考资料: 这条评论太长了,所以我把它作为一个答案发布。我认为有两个潜在的分歧来源。首先,我的理解是,boxplot指的是boxplot.stats,它使用与

据我所知,方框图中的方框末端分别表示25%和75%的分位数,中间值=50%。因此,它们应该等于
draw_quantiles=c(0.25,0.5,0.75)
参数中由
geom_小提琴
绘制的0.25/0.5/0.75分位数

中位数和50%分位数拟合。然而,0.25和0.75分位数都不适合箱线图的箱端(见图,尤其是“virginica”面)

参考资料:


  • 这条评论太长了,所以我把它作为一个答案发布。我认为有两个潜在的分歧来源。首先,我的理解是,
    boxplot
    指的是
    boxplot.stats
    ,它使用与分位数非常相似但不一定相同的
    铰链<代码>?boxplot.stats
    表示:

    两个“铰链”是第一个和第三个四分位数的版本,即:。, 接近分位数(x,c(1,3)/4)。铰链等于奇数的四分位数 n(其中n第二个因素似乎是主要原因。这里有更多的证据支持这一点

    通过切换到,可以根据经验确认差异是由于使用核密度估计来计算分位数而不是实际观测值的
    geom_小提琴
    造成的。例如,如果我们强制使用宽带(
    bw=1
    ),则估计密度将过度平滑,并进一步偏离箱线图中使用的基于观测的分位数:

    by(d$Sepal.Length, d$Species, function(x) boxplot.stats(x, coef=5)$stats )
    by(d$Sepal.Length, d$Species, function(v) quantile(density(v)$x))
    


    因此,是的,小心这一点-密度估计的参数可能会影响结果!

    你的答案是有意义的,谢谢!我在所有这些分位数值修改中看到的问题(无论是“铰链”还是密度估计)都是指最后意义上的“分位数”“上铰链,75%分位数”,而
    geom_小提琴
    doc直接将其称为“draw_分位数”。这允许用户假设处理相同的统计数据,而实际上两者都不同。
    by(d$Sepal.Length, d$Species, function(x) boxplot.stats(x, coef=5)$stats )
    by(d$Sepal.Length, d$Species, function(v) quantile(density(v)$x))
    
    require(ggplot2)
    require(cowplot)
    
    theme_set(cowplot::theme_cowplot())
    
    d = iris
    
    ggplot2::ggplot(d, aes(factor(0), Sepal.Length)) + 
      stat_ydensity(bw=1, fill="black", alpha=0.2, draw_quantiles = c(0.25, 0.5, 0.75)
                  , colour = "red", size = 1.5) +
      stat_boxplot(geom ='errorbar', width = 0.1)+
      geom_boxplot(width = 0.2)+
      facet_grid(. ~ Species, scales = "free_x") +
      xlab("") + 
      ylab (expression(paste("Value"))) +
      coord_cartesian(ylim = c(3.5,9.5)) + 
      scale_y_continuous(breaks = seq(4, 9, 1)) + 
      theme(axis.text.x=element_blank(),
            axis.text.y = element_text(size = rel(1.5)),
            axis.ticks.x = element_blank(),
            strip.background=element_rect(fill="black"),
            strip.text=element_text(color="white", face="bold"),
            legend.position = "none") +
      background_grid(major = "xy", minor = "none")