我坚持将我的箱线图从高到低重新排序。我试过fct_reorder
很多次,但我想我没听懂
我的数据:
dat <- structure(list(Pesticide = c(
"Mancozeb", "Mancozeb", "Benomyl",
"DDT", "Glyphosate", "Carbofuran", "Carbofuran", "Aldicarb",
"Chlorsulfuron", "Neem", "Oxadiazon", "Oxyfluorfen", "Phorate",
"Phorate", "Fenvalerate", "Fenvalerate", "BHC", "BHC", "Diallate",
"Cycloate", "PCA", "Lenacyl", "Phenmedipham", "Aldrin"
), Change = c(
-11.2,
-5.6, 33.9, -40, 36.4, -5, -38, -94.6, -16, -49.5, 32.3, 37.5,
15.9, 22.2, 3.8, 17.6, 27.7, 28.2, 66.3, 33.5, 36, 10.3, 139.8,
18
)), class = "data.frame", row.names = c(NA, -24L))
我的代码:
library(ggplot2)
library(tidyverse)
library(ggExtra)
library(forcats)
theme_set(theme_bw())
dat<-read.delim("clipboard")
summary(dat)
q<-qplot (fct_reorder(Pesticide, Change,data=dat, geom=c("boxplot"),
fill=Pesticide, xlab="Pesticide", ylab="% Change in Nitrification"))
r<-q + theme(axis.text.x = element_text(angle = 45, hjust = 1))
r+geom_hline(yintercept =0,linetype="dashed",size=0.75,color="red")