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.
On Thu, Jun 28, 2012 at 2:41 AM, LCOG1 <jroll at lcog.org> wrote:> 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. ?ThanksThe latter would be the better approach. You haven't given code, but you probably didn't add 'breaks=NULL', and without it all panels will have a common set of breakpoints, so scales effectively will be the same in all panels. This works for me: xx <- exp(rnorm(1000)) DF <- data.frame(UnitArea = c(xx, log(xx)), Type = c(rep("Base",1000), rep("Log",1000))) histogram( ~ UnitArea | Type, data = DF, 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))) }, breaks = NULL, col = Colors.[color], layout = c(1, 2), scales = list(x = list(relation = 'free')))> 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.Yes, see ?plot.trellis. -Deepayan