[R] Superimposing Line over Histogram in Density Plot

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Mon Jun 16 09:05:31 CEST 2008


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

----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Gundala Viswanath" <gundalav at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, June 16, 2008 8:25 AM
Subject: [R] Superimposing Line over Histogram in Density Plot


> Hi,
>
> 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__
>
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> R-help at 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.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list