Plotting column names as x-axis in R

后端 未结 1 1457
心在旅途
心在旅途 2021-01-21 19:28

I have the following data frame:

rs = data.frame(c(\"A1\",\"A2\",\"A3\",\"A4\",\"A5\"), runif(5), runif(5), runif(5))
names(rs)=c(\"column\", 2007,2008,2009)
row         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 19:44

    rs      <- as.data.frame(t(rs))
    rs$year <- rownames(rs)
    rs      <- melt(rs, id.vars=c("year"))
    
    
    ggplot(rs, aes(x=as.numeric(year), y=value, color=variable)) + geom_line()
    

    For multiple plots per page there are many solutions.

    Simple example:

    http://theanalysisfactor.com/r-multiple-graphs

    Better example:

    http://cran.r-project.org/web/packages/egg/vignettes/Ecosystem.html

    0 讨论(0)
提交回复
热议问题