我有一个六列的矩阵。我想分别绘制每一列。
首先我创建矩阵:
a<-replicate(6,rnorm(100))
colnames(a)<-c("one", "two", "three", "four", "five","six")
然后我melt()
变量:
b<-melt(a, id.vars=1:6)
colnames(b)<-c("c","variable","value")
现在我想绘制这些变量:
ggplot(b,aes(x = c, y = value, colour = variable, linetype = variable,size = variable)) +
geom_line() +
scale_x_continuous(breaks=seq(0,100,5)) +
scale_colour_manual(values=c("blue1", "blue1","blue1","blue1","blue1","blue1")) +
scale_linetype_manual(values = c(0,0,1,0,0,0)) +
scale_size_manual(values = c(0.2,0.2,0.2,0.2,0.2,0.2)) +
xlab("\nT") +
ylab("O\n") +
theme_bw()
但是,不是按照指定的“一”、“二”、“三”等顺序绘制变量,而是将顺序混合为:五四一六三二。如何按指定的列名顺序绘制变量?