将数据框的列名称作为每列图的标题 [英] Put column names of a data frame as the title of plots of each column

查看:35
本文介绍了将数据框的列名称作为每列图的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含36列和3000多个行的数据框。我在 for循环内使用plot函数来绘制每列的图形。我希望图的标题显示为列名。我怎样才能做到这一点?

I have a data frame with 36 columns and more than 3000 rows. I am using plot function inside a for loop to plot graphs of each column. I want the title of the graph to appear as column name. How can I do that?

for(i in c(1:36)){
  plot(DowData[,i],type="l",main="colnames(DowData)[i]")
}


推荐答案

使用 lapply 您可以遍历列名:

 invisible(lapply(colnames(DowData),function(x){
      plot(DowData[,x],main=x,type="l")
    }))

这篇关于将数据框的列名称作为每列图的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆