简体   繁体   English

如何在 R 中使用 Plotly 将平均值添加到 BoxPlot?

[英]How to add mean value to a BoxPlot using Plotly in R?

Creating a boxplot with Plotly library in R is straightforward as follows:在 R 中使用 Plotly 库创建箱线图很简单,如下所示:

library (plotly)

x <- 1:100

plot_ly (x = ~x, type = 'box' )

But, by default it gives me median, while I want the value of Mean instead.但是,默认情况下它给了我中位数,而我想要 Mean 的值。 I know that I can change this with schema() but I could not figure it out how.我知道我可以用 schema() 改变它,但我不知道如何改变。 I also do not want to calculate it myself and then add that to the plot, I want the plot to do it by changing that default behavior.我也不想自己计算然后将其添加到绘图中,我希望绘图通过更改默认行为来完成。

Cheers干杯

Data with mean not equal the median:均值不等于中位数的数据:

x <- c(1:10, 40:50)

plot_ly (x = ~x, type = 'box', boxmean = T)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM