![](/img/trans.png)
[英]How to create a boxplot in R, with box representing the 15th and 85th percentiles, rather than the default 25th and 75th?
[英]How to change 25% and 75% quantile line type and color in a boxplot in R?
我現在正在處理一些數據,我想制作一個箱線圖。 我注意到,可以通過設置medlty
和medcol
來更改中位數的medlty
和medcol
。
我想知道如何在箱圖中更改25%和75%的分位數線類型和顏色? 例如,是否可以將行類型2和藍色設置為25%的分位數,而將行類型3和綠色設置為75%的分位數?
set.seed(123)
Mydata = sample(x=100:300, size = 500, replace = T)
Mydata = c(Mydata, 1, 500)
boxplot(Mydata,medcol="red", medlty=3)
使用tidyverse的ggplot。 檢查是否有幫助!
library(tidyverse)
Mydata = tibble(dist = sample(x=100:300, size = 500, replace = T))
Mydata %>% ggplot(aes(x = 1, y = dist)) + geom_boxplot()+
geom_hline(data = quantile(Mydata$dist), yintercept = quantile(Mydata$dist)[2], lty = 2, color = "blue", lwd= 1) +
geom_hline(data = quantile(Mydata$dist), yintercept = quantile(Mydata$dist)[4], lty = 3, color = "green", lwd = 1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.