On 30-Nov-09 11:09:12, Trafim wrote:
> Dear all,
> I cannot find a function which would allow drawing hist and density
> on the same graph.
> 
> x <- seq(1,40,1)
> y <- 2*x+1+5*rnorm(length(x))
> 
> hist(y,freq = FALSE)
> plot(density(y))
> 
> thanks a lot for the help

plot() initiates a completely new plot, and therefore erases what
was there before. Use lines(), or points(), instead:

  x <- seq(1,40,1)
  y <- 2*x+1+5*rnorm(length(x))
  
  hist(y,freq = FALSE)
  lines(density(y))

lines() *adds* extra elements (line segments) to an *existing* plot.

See ?plot abd ?lines (and also ?points) for more explanation.
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 30-Nov-09                                       Time: 11:27:49
------------------------------ XFMail ------------------------------

______________________________________________
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