[R] Plotting Y axis labels within a loop

David Winsemius dwinsemius at comcast.net
Wed Oct 13 00:26:45 CEST 2010


On Oct 12, 2010, at 5:54 PM, Steve Swope wrote:

>
> When I plot y axis labels with in a loop they (I) get confused. Here  
> is some
> sample code:
>
> Fe<-c(1.1, 4.5, 7.2, 8.8)
> Mn<-c(9.6, 7.2, 5.3, 2.1)
> Cd<-c(2.2, 3.4, 6.1, 3.2)
> FeMnCd<-data.frame(Fe, Mn, Cd)
>
> par(mfrow=c(2,2))
>
> for(i in FeMnCd)plot(i, xlab="Event",ylab=colnames(FeMnCd)[i])
>
> The more plots per page, the crazier it gets! TIA

Think about what will be assigned to "i" and perhaps even print it to  
your console, since it's not what you apparently expect:

  for(i in FeMnCd){print(i); plot(i, xlab="Event",ylab=colnames(FeMnCd) 
[i]) }

The source of you confusion may become more clear.


>
> Steve
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Plotting-Y-axis-labels-within-a-loop-tp2992813p2992813.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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list