x <- rnorm(1000) hist(x, freq = FALSE, col = "grey") curve(dnorm, col = 2, add = TRUE)
This thread (specifically the Ted Harding answer) from the r-help-list augments the usefulness of this simple tip.
This kind of plots cab be easily produced using the lessR package.
For example, from ?color.density:
library(lessR) # generate 100 random normal data values y <- rnorm(100) # normal curve and general density curves superimposed over histogram # all defaults color.density(y)
Your code doesn't work. Even with hist() on another line. I took out the freq and col options to get a histogram plotted, but the curve function plots a horizontal line at approximately 0. I'm using ver2.9.
RispondiEliminaIt does work. My guess:
RispondiElimina1) you should divide each command using the ; character or type each command in a different row.
2) the " character of "grey" after copy & paste became “, so you have to substitute it with the " of your keyboard.
Hope it helps.
Great, Thank you!
RispondiEliminaYou're welcome! :-)
RispondiEliminaSay I have 3 sets of data, how to do 3 histograms grouped by bin and overlaid by 3 density curves on one graph?
RispondiEliminamutlhist in plotrix can do the 3 histograms together , but how to add density? Thanks!
I think that both lattice and ggplot2 packages should be capable to solve your problem. Please take a look at the information you can find at the following link:
RispondiEliminahttp://goo.gl/0K55j
In particular, you can download a pdf comparing the two packages in all kind of common visualizations: it can be an useful starting point.
HIH!