r - Align axis ticks with bins in a lattice histogram -


i plotted histogram using lattice

histogram(~time |factor(bila), data=flexi2, xlim= c(5, 15), ylim=c(0, 57),       scales=list(x=list(at=seq(5,15,1))), xlab="time",        subset=(bila%in% c("")))` 

the bins not match exact hours, whereas bin start @ exact hour, example, 6,7 etc. use lattice since want conditional histograms. have extracted here 1 histogram illustrate. enter image description here

update: here reproducible example (i hope) requested. can seen 0 example not @ limit of bins.

x<-rnorm(1000) histogram(~x) 

enter image description here

this happens because specified x axis scale scales = list(x = list(at = 5:15)), didn't change breakpoints. happens in default case well: default axis labels integers, default breakpoints determined programmatically , not integers unless have integer-valued data.

an easy fix specify own breaks in breaks argument:

histogram(~time |factor(bila), data=flexi2, subset=(bila %in% c("")),   xlim= c(5, 15), ylim=c(0, 57),   breaks = 5:15,   scales = list(x = list(at = 5:15)),   xlab="time") 

and example:

library(lattice) x <- rnorm(1000) x[abs(x) > 3] <- 3 x_breaks <- c(-3, -1.5, 0, 1.5, 3) histogram(~ x,           title = "defaults") histogram(~ x, breaks = x_breaks,           title = "custom bins, default tickmarks") histogram(~ x, scales = list(x = list(at = x_breaks)),           title = "custom tickmarks, default bins") histogram(~ x, breaks = x_breaks, scales = list(x = list(at = x_breaks)),           title = "custom tickmarks, custom bins") 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -