df1 <- data.frame(a=c(1,4,7),
b=c(3, 5, 6),
c=c(1, 1, 4),
d=c(2 ,6 ,3))
df2<-data.frame(id=c("a","b","b","c","c","c","d","d"),
var=c(12,20,15,18,10,30,5,8))
mediorder <- with(df2, reorder(id, -var, median))
boxplot(var~mediorder, data = df2)
#boxplot of df1 in order "c,b,a,d"
boxplot(df1) # ??
您好, 我有以上两个数据帧。对于df2,我根据中值对x轴进行了编码。我想用d轴制作一个df1的箱线图,其顺序与df2(c,b,a,d)的顺序相同。我的实际数据集太大,无法手动订购。 有任何想法吗? 谢谢
答案 0 :(得分:0)
fc = levels(as.factor(mediorder))
ndf1= df1[, order(fc)]
boxplot(ndf1)