我想按照它們的第 80 個百分位值的順序重新排序我的箱線圖。
我的情節是這樣的:

我的代碼結構是這樣的:
ggplot(data, aes(x=reorder(y, x, median), y))
geom_boxplot(fill="deepskyblue")
stat_boxplot(geom ='errorbar', width=0.3)
theme_bw()
scale_y_continuous(trans="log10", n.breaks = 6)
目前我按中位數訂購它們。我有兩個問題:
看起來它按中位數對箱線圖進行排序,直到大約 1/3 的圖,然后回傳到隨機排序。為什么會這樣?
我如何輕松地按第 80 個百分位訂購?我試圖在底層
quantile(0.8, y)的median,但得到一個錯誤。
不幸的是,我不能將資料結構/變數作為機密共享。
謝謝。
uj5u.com熱心網友回復:
沒有按順序排列圖形的問題可能是由于
NAs,請嘗試過濾它們:data <- data %>% filter(!is.na(y))try
FUN = quantile, prob = 0.80,在reorder函式中你會得到:ggplot(data, aes(x=reorder(y, x, FUN = quantile, prob=0.80), y)) geom_boxplot(fill="deepskyblue") stat_boxplot(geom ='errorbar', width=0.3) theme_bw() scale_y_continuous(trans="log10", n.breaks = 6)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/358896.html
