我创建了一个25个时间序列的ggplot矩阵。现在我想重新排列时间序列,这样小麦就在 rice 旁边...... 这是我的代码:
data_std <- data
for (i in 2:26)
{data_std[,i] <- (data_std[,i] - mean(data_std[,i])) / sd(data_std[,i])}
# Create the new dataframe "datalili"
newdata_wheat <- data_std[,1:2]
names(newdata_wheat)[2]<-paste("price")
newdata_wheat["commodity"] <- "wheat"
datalili <- newdata_wheat
for (i in 3:26)
{ data_new <- data_std[,c(1,i)]
names(data_new)[2]<-paste("price")
com <- colnames(data_std)[i]
data_new["commodity"] <- com
datalili = rbind(datalili,data_new)}
# Plot
ggplot(datalili, aes(x=time, y=price, group=commodity, colour='red')) + geom_line() + facet_wrap( ~ commodity)
在我的结果中,ob。按字母顺序重新排列,但我想按顺序排列以下顺序:c(1,2,3,4,5,6,24,25,2,7,8,9,10,11,12, 13,14,15,16,17,18,19,20,21,20,23)
我试过了:
ggplot(datalili, aes(x=time, y=price, group=commodity, colour='red'), **layout=c(1,2,3,4,5,6,24,25,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,20,23)**) + geom_line() + facet_wrap( ~ commodity) but it did not work out.
提前谢谢!
以下是我的情节的当前版本:
http://127.0.0.1:9611/graphics/plot_zoom_png?width=1192&height=697