Overlay histogram with density curve

Here you go! # create some data to work with x = rnorm(1000); # overlay histogram, empirical density and normal density p0 = qplot(x, geom = ‘blank’) + geom_line(aes(y = ..density.., colour=”Empirical”), stat=”density”) + stat_function(fun = dnorm, aes(colour=”Normal”)) + geom_histogram(aes(y = ..density..), alpha = 0.4) + scale_colour_manual(name=”Density”, values = c(‘red’, ‘blue’)) + theme(legend.position = c(0.85, … Read more

Histogram using gnuplot?

yes, and its quick and simple though very hidden: binwidth=5 bin(x,width)=width*floor(x/width) plot ‘datafile’ using (bin($1,binwidth)):(1.0) smooth freq with boxes check out help smooth freq to see why the above makes a histogram to deal with ranges just set the xrange variable.

Scatterplot with marginal histograms in ggplot2

This is not a completely responsive answer but it is very simple. It illustrates an alternate method to display marginal densities and also how to use alpha levels for graphical output that supports transparency: scatter <- qplot(x,y, data=xy) + scale_x_continuous(limits=c(min(x),max(x))) + scale_y_continuous(limits=c(min(y),max(y))) + geom_rug(col=rgb(.5,0,0,alpha=.2)) scatter

Overlay normal curve to histogram in R

Here’s a nice easy way I found: h <- hist(g, breaks = 10, density = 10, col = “lightgray”, xlab = “Accuracy”, main = “Overall”) xfit <- seq(min(g), max(g), length = 40) yfit <- dnorm(xfit, mean = mean(g), sd = sd(g)) yfit <- yfit * diff(h$mids[1:2]) * length(g) lines(xfit, yfit, col = “black”, lwd = … Read more

Fitting a density curve to a histogram in R

If I understand your question correctly, then you probably want a density estimate along with the histogram: X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4)) hist(X, prob=TRUE) # prob=TRUE for probabilities not counts lines(density(X)) # add a density estimate with defaults lines(density(X, adjust=2), lty=”dotted”) # add another “smoother” density Edit a long while … Read more

How to plot two histograms together in R?

Here is an even simpler solution using base graphics and alpha-blending (which does not work on all graphics devices): set.seed(42) p1 <- hist(rnorm(500,4)) # centered at 4 p2 <- hist(rnorm(500,6)) # centered at 6 plot( p1, col=rgb(0,0,1,1/4), xlim=c(0,10)) # first histogram plot( p2, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T) # second The key is that the colours are … Read more

Histogram in Haskell [closed]

We can start by generating ranges required, and then map count function onto ranges to get list of partial functions, which finally can be applied on the given list. ranges lim n = takeWhile (\(x,y) -> x < lim) [(k*n, (k+1)*n – 1) | k <- [0..]] count (l,r) = length.filter (\x -> l <= … Read more