[R] lattice histogram log and non log values

LCOG1 jroll at lcog.org
Wed Jun 27 23:11:58 CEST 2012


Hello all, 
  Please consider the following

library(lattice)
Colors. <-rep(brewer.pal(7, "Dark2"),2)
color <- 1

Data.X.. <- data.frame(UnitArea = c(rnorm(1000), rnorm(1000)), Type =
c(rep("Base",1000),rep("Log",1000)))
		
			histogram( ~ UnitArea |  Type, data = Data.X..,
          xlab = "Unit Area", type = "density",
          panel = function(x, ... ){
              panel.histogram(x, ...)
              panel.mathdensity(dmath = dnorm, col = "black",
                                args = list(mean=mean(x),sd=sd(x)))
          }, col = Colors.[color], layout = c(1, 2),
		   scales=list(log = c(F,T),tick.number=list(8), rot = c(0, 90),
                 x = list(relation = 'free')))

I want to plot on the same page distributions both observed values and the
logged values.  I tried using the log parameter e.g. log = c(F,T) but I dont
think this is right.    When I tried transforming the data before plotting
the scales were all messed up. Guidance would be appreciated.  Thanks

Also, is there a way to simply plot multiple panels like the base graphics
package using  par(new = TRUE) in the following?  It just replaces the first
plot so maybe I shouldn't be trying to use the lattice package with the base
graphics package. 

#Set plot paramerters
par(mfrow=c(3,2), oma=c(3,3,3,3))

		#Base
		Data.X <- rnorm(100)
		histogram( ~ Data.X,
          xlab = "Unit Area (Log Transformed)", type = "density",
          panel = function(x, ...) {
              panel.histogram(x, ...)
              panel.mathdensity(dmath = dnorm, col = "black",
                                args = list(mean=mean(x),sd=sd(x)))
          }, col = Colors.[color], layout = c(1, 2))

           par(new = T)
		#Transform
		Data.X <- log( rnorm(1000))
		histogram( ~ Data.X,
          xlab = "Unit Area (Log Transformed)", type = "density",
          panel = function(x, ...) {
              panel.histogram(x, ...)
              panel.mathdensity(dmath = dnorm, col = "black",
                                args = list(mean=mean(x),sd=sd(x)))
          }, col = Colors.[color], layout = c(1, 2))

--
View this message in context: http://r.789695.n4.nabble.com/lattice-histogram-log-and-non-log-values-tp4634667.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list