Re: [R] Creating plots for all variables in a data frame and printing them with the variable name in the main title

From: bartjoosen <bartjoosen_at_hotmail.com>
Date: Mon, 17 Mar 2008 08:04:55 -0700 (PDT)

Here is one way:
lapply(1:ncol(x),function(i) hist(x[,i], main =paste("Histogram of",names(x)[i])))

Bart

Uli Kleinwechter wrote:
>
> Dear all,
>
> I'm just trying to create plots for all variables in a dataframe (named
> "x") using the following:
>
> png()
> apply(x,2,hist)
>
> Just as intended, it produces one plot for each variable. Unfortunately,
> the main title of each graph is "Histogram of newX[,i]" instead of
> "Histogram of name of variable". This makes it impossible to assign the
> graphs to the variables. Is there a way to change this and to make R use
> the correct variable names in the title of the plot?
>
> Thank you very much,
>
> Uli
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

-- 
View this message in context: http://www.nabble.com/Creating-plots-for-all-variables-in-a-data-frame-and-printing-them-with-the-variable-name-in-the-main-title-tp16092442p16093308.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 17 Mar 2008 - 15:13:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Mar 2008 - 15:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive