1

I have a data frame with 76 columns of an equal number of species, I want to plot in different plots each species using a loop. However, I want to use the colnames to obtain each plot with the name of each species. Someone could help me with my problem.

I use the following expression in the loop:

title(main=expression(paste("density of",colnames(df))))

I tried with this one:

title(main=expression(paste("density of",colnames(df[,i]))))

Thank you

neilfws
  • 32,751
  • 5
  • 50
  • 63
  • 1
    Hi Juan - You need to give us some of your data to work with. – Dom Apr 23 '18 at 06:10
  • Possible duplicate of [Put column names of a data frame as the title of plots of each column](https://stackoverflow.com/questions/20881093/put-column-names-of-a-data-frame-as-the-title-of-plots-of-each-column) – A. Suliman Apr 23 '18 at 06:22

1 Answers1

1
for (i in seq_along(colnames(iris))){
  hist(iris[,i],main=paste("density of",names(iris)[i]))
    }
A. Suliman
  • 12,923
  • 5
  • 24
  • 37