[R] overlay lattice histograms with goodness-of-fit pdfs
Frede Aakmann Tøgersen
FredeA.Togersen at agrsci.dk
Mon Sep 10 12:40:26 CEST 2007
The following is one of the examples in the help page for histogram:
histogram( ~ height | voice.part, data = singer,
xlab = "Height (inches)", type = "density",
panel = function(x, ...) {
panel.histogram(x, ...)
panel.mathdensity(dmath = dnorm, col = "black",
args = list(mean=mean(x),sd=sd(x)))
} )
This should give you some thing to start from.
Also using the subset argument of the lattice functions will make make your code more readable. Instead of your code
histogram(~ data | month * station,
data = sta.stack[sta.stack[,"type"]=="precip" & (sta.stack[,"month"]=="Dec" | sta.stack[,"month"]=="Jan" | sta.stack[,"month"]=="Feb"),],
xlab = "Precipitation (mm)")
you can use (not tested because you didn't supply a reproducable example)
histogram(~ data | month * station, data = sta.stack
subset = type==precip & month %in% c("Dec", "Jan", "Feb"),
xlab = "Precipitation (mm)")
Med venlig hilsen
Frede Aakmann Tøgersen
> -----Oprindelig meddelelse-----
> Fra: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] På vegne af Brad
> Christoffersen
> Sendt: 10. september 2007 12:08
> Til: R-help at stat.math.ethz.ch
> Emne: [R] overlay lattice histograms with goodness-of-fit pdfs
>
> Hello,
>
> I am new to R exploratory data analysis and plotting. Is
> anyone aware of a way to overlay a set of conditional
> histograms with conditional PDFs? Below, I generate a
> lattice plot of precipitation histograms based on different
> months and stations, given a subset of the dataset:
>
>
> histogram(~ data | month * station,
> data = sta.stack[sta.stack[,"type"]=="precip" &
> (sta.stack[,"month"]=="Dec" | sta.stack[,"month"]=="Jan" |
> sta.stack[,"month"]=="Feb"),],
> xlab = "Precipitation (mm)")
>
>
> I previously used a combination of the low-level 'lines()'
> and 'dgamma()'
> functions to overlay a gamma PDF onto a single histogram.
> Now what I would like to do is to do the same thing, but with
> a function that allows me to specify a formula similar to
> that in the histogram function above
>
> [SomeKindOfPDF] ~ [x-range] | month * station
>
> which will plot the PDF with the appropriate factors (month
> and station).
>
> All I'm looking for is for someone to get me going in the
> right direction with a useful package or function to use.
>
> Any help is much appreciated!
> Brad Christoffersen
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
More information about the R-help
mailing list