ggplot中的图表顺序

时间:2016-01-27 19:28:47

标签: r

如何修改此代码以根据变量的顺序为我提供图表。我的意思是,AverageTime的第一个图,A的第二个图和AverageCost的第三个图。

Type<-c("a","b","c","d","e","f","g","h","i","j","k","OG","HH")
    AverageTime<-c(66,367,55,700,200,45,44,55,55,6,66,66,400)
    A<-c(11,3,13,70,55,66,44,8,55,6,66,9,400)
    AverageCost<-c(300,10000,200,20000,500000,NA,700,NA,400000,NA,120000,1200,450)
    df<-data.frame(Type,AverageTime,A,AverageCost)

    df %>%
      mutate(AverageCost=as.numeric(AverageCost),A=as.numeric(A), AverageTime=as.numeric(AverageTime)) %>%
      gather(variable, value, -Type) %>%
      ggplot(aes(x=Type, y=value, colour=variable, group=variable)) +
      geom_line() +
      facet_wrap(~variable, scales="free_y")

0 个答案:

没有答案