R 标签的侧箱线图比较

R 标签的侧箱线图比较,r,boxplot,R,Boxplot,这是我的数据集dput\u data dput_data <- structure(list(Label = c(" Flight", " Flight", " Flight", " Flight", " Flight", " Ground Control", " Ground Control", " Ground Control", " Ground Control", " Ground Control", " Ground Control"), `210885` = c(2.467

这是我的数据集
dput\u data

dput_data <- structure(list(Label = c(" Flight", " Flight", " Flight", " Flight", 
" Flight", " Ground Control", " Ground Control", " Ground Control", 
" Ground Control", " Ground Control", " Ground Control"), `210885` = c(2.46726120893655, 
-0.174636990542105, -0.463404328357544, 2.3996395908089, -0.150507030748742, 
5.64497005685753, 3.36669883823842, 0.0291245138878325, -0.0720040453347311, 
1.23592496897254, -0.435680321628551), `110647` = c(-0.183451995597915, 
-0.232101174582698, -0.418549509261665, 3.12474114229781, -0.963627404680163, 
-0.295591624345765, 3.74110668642539, -0.307620588051106, 4.95070981495709, 
-0.248418667713625, 0.556071497195402), `120996` = c(2.958740197185, 
-0.658764097795927, -0.720985892268865, -0.605140415143121, -0.614856607147667, 
2.84170000321244, 2.4703391289031, 1.89042697528755, 1.38117056072924, 
2.66548725562505, -0.775258323014181)), class = "data.frame", row.names = c(35L, 
36L, 37L, 38L, 39L, 44L, 45L, 46L, 47L, 48L, 49L))
目前我已尝试:

library(reshape2)
dput_dat <- melt(dput_data, id.vars = 'Label', measure.vars = c('210885', '110647', '120996'))
library(ggplot2)
ggplot(dput_dat) + geom_boxplot(aes(y=value, color=variable)) + facet_grid(.~`Label`)
library(重塑2)

dput_dat使用Label作为x变量,使用您的变量进行镶嵌,具体如下:

库(tidyverse)
数据%>%pivot\u更长(-Label,names\u to=“type”,values\u to=“value”)%%>%
排列(描述(类型))%>%
突变(类型=因子(类型,级别=唯一(类型))%>%
ggplot(aes(x=标签,y=值,颜色=标签))+
geom_箱线图()+
面_包裹(~type)


这就是你要找的吗?

哦,我本来希望飞行控制和地面控制的颜色不同。但这仍然是可以接受的。你知道我怎么把这些图(从左到右-210885110647120996)排序吗?不客气。我编辑了我的答案,向您展示了如何设置标签的颜色,以及如何设置镶嵌面的所需顺序。让我知道它是否适合你。哦,谢谢!我注意到您对订单使用了降序,是否可以自己指定订单?对不起,我没有注意到订单没有降序。您可以通过
mutate(type=factor(type,levels=c(“210885”、“110647”、“120996”))
删除排列并更改
mutate
函数,该函数应该可以工作
library(reshape2)
dput_dat <- melt(dput_data, id.vars = 'Label', measure.vars = c('210885', '110647', '120996'))
library(ggplot2)
ggplot(dput_dat) + geom_boxplot(aes(y=value, color=variable)) + facet_grid(.~`Label`)