I do it a bit differently:
Once you've got myhist, you can plot a line on the existing histogram plot with something like:

smoo<-spline(myhist$breaks[1:length(myhist$breaks)-1],myhist$counts)
lines(smoo$x,smoo$y,col='green')

You'll have to muck a bit with scale factors to make the spline curve "match up" with the histogram plot's actual x-axis values. (actually, that snippet is part of my conversion from histogram data to a bar chart that "looks" like a histogram, with the spline curve overlaid).

Carl





try something like this:

x <- rnorm(200)
hist(x, col = "blue", freq = FALSE)
lines(density(x), col = "red", lwd = 2)

I hope it helps.

Best,
Dimitris


>
> Currently I have a density plot generated with this
> snippet.
>
> Is there a way I can add a line curve on top of it?
> I mean in one figure
>
>
> __BEGIN__
> myhist <- hist(x
> col="blue",
> main = "Density Plot",
> xlab = "Exp Level",
> )
> __END__
>
>

______________________________________________
R-help@r-project.org 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.

Reply via email to