I want to reorder my boxplots in order of their 80th percentile values.
my plot looks like this:
my code structure is along the lines of:
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)
currently ive ordered them by median. I have two questions:
it looks like it orders the boxplots by the median up til about 1/3rd of the plot, then goes back to random ordering. Why would this be?
how can i easily order it by the 80th percentile? i tried subbing in
quantile(0.8, y)
formedian
but get an error.
i unfortunately can't share the data structure/variables as its confidential.
Thanks.
CodePudding user response:
The problem of not having the graph in order may be due to
NA
s, try filtering them previously:data <- data %>% filter(!is.na(y))
try
FUN = quantile, prob = 0.80
, in thereorder
function you will end up with: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)