Brad Christoffersen
2007-Sep-10 10:08 UTC
[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
Frede Aakmann Tøgersen
2007-Sep-10 10:40 UTC
[R] overlay lattice histograms with goodness-of-fit pdfs
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. >
Apparently Analagous Threads
- Function that is giving me a headache- any help appreciated (automatic read )
- Problems with a specific calculate.
- summing 15 minute precip data to daily
- R combining vectors into a data frame but without a continuous common variable
- readMat - how to retrieve the variables