Plot doesn't create an object to be plotted later like in ggplot: rather it, by default, makes a new plot and erases the histogram. 

> hist(z)
> lines(z, y, lwd = 1)

should work, though you may need to add freq=FALSE to hist()

MW

On Nov 1, 2011, at 6:42 PM, Jim Silverton <jim.silverton@gmail.com> wrote:

> I need a plot with a histogram z and a plot of z versus y superimposed.
> This is not working...
> z = rnorm(1000)
> y = rnorm(1000,1,2)
> hist(z)
> dx = plot(z, y, lwd = 1)
> lines(dx, add=TRUE)
> 
> 
> 
> -- 
> Thanks,
> Jim.
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

	[[alternative HTML version deleted]]

