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","f","f","b","b","c","c","c","d","d"),
var=c(12,20,15,18,10,30,5,8,5,5))
mediorder <- with(df2, reorder(id, -var, median))
boxplot(var~mediorder, data = df2)
fc = levels(as.factor(mediorder))
ndf1= df1[,intersect(fc, colnames(df1))]
ln<-lm( #confused here
boxplot(ndf1)
abline(ln)
我有上面的boxplot(ndf1),x轴根据另一个数据框的中位数排序,我想为它添加一个趋势线。
我感到困惑,因为它没有引用x和y变量,只有带有计数的列。订购也导致了我的问题。
编辑澄清...... 我在这里提出问题:How to match an ordered list (e.g., levels(as.factor(x)) ) to another dataframe in which only some columns match?
我想做的就是为ndf1
设置趋势线