An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110524/06e331d7/attachment.pl>
histogram with density
5 messages · Steve Lianoglou, Rekha, Peter Ehlers
Hi,
On Mon, May 23, 2011 at 11:41 PM, Rekha <chithralekha86 at gmail.com> wrote:
Hello All,* *I want to draw a histogram with density curve. * *For that simply i created a data called*"x" *and i used the function called * ? ?hist(x, col = "blue", freq = FALSE),** ? *from this function i got a histogram*. *After that , i tried this function* ?** lines(density(x), col = "red", lwd = 2 ?) ?*but i could not get the density curve. So, Again i used ?other function* ? ?curve(dnorm, col = 2, add = TRUE)** *instead of the previous function for density curve. but still am getting error in R ?like this: ?Error in plot.xy(xy.coords(x, y), type = type, ...) ?plot.new has not been called yet" * ?I have used below codes to have a data and histogram with density curve" x <- rnorm(200) hist(x, col = "blue", freq = FALSE) lines(density(x), col = "red", lwd = 2)
You should use the code above. I don't get it though -- this is working fine for me. Are you getting the "plot.new" error for both versions of your code? Although I feel like in 99% of the time this won't be necessary, but what happens if you call `plot.new()` before your call to hist? eg: R> x <- rnorm(200) R> plot.new() R> hist(x, col = "blue", freq = FALSE) R> lines(density(x), col = "red", lwd = 2) Does that work? If not -- what if you use `dev.new()` in place of `plot.new()`? -steve
Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110524/21c649be/attachment.pl>
On Tue, May 24, 2011 at 12:31 AM, Rekha <chithralekha86 at gmail.com> wrote:
S . Am getting error still now if i use both version of the codes . i have to call any library?
No. The code you've written here doesn't require loading any other R libraries. Please copy and paste the exact code you've entered along with the *exact* error you are getting. Also, what is the result of sessionInfo()? -steve
On Tue, May 24, 2011 at 9:22 AM, Steve Lianoglou <mailinglist.honeypot at gmail.com> wrote:
Hi, On Mon, May 23, 2011 at 11:41 PM, Rekha <chithralekha86 at gmail.com> wrote:
Hello All,* *I want to draw a histogram with density curve. * *For that simply i created a data called*"x" *and i used the function called * ? ?hist(x, col = "blue", freq = FALSE),** ? *from this function i got a histogram*. *After that , i tried this function* ?** lines(density(x), col = "red", lwd = 2 ?) ?*but i could not get the density curve. So, Again i used ?other function* ? ?curve(dnorm, col = 2, add = TRUE)** *instead of the previous function for density curve. but still am getting error in R ?like this: ?Error in plot.xy(xy.coords(x, y), type = type, ...) ?plot.new has not been called yet" * ?I have used below codes to have a data and histogram with density curve" x <- rnorm(200) hist(x, col = "blue", freq = FALSE) lines(density(x), col = "red", lwd = 2)
You should use the code above. I don't get it though -- this is working fine for me. Are you getting the "plot.new" error for both versions of your code? Although I feel like in 99% of the time this won't be necessary, but what happens if you call `plot.new()` before your call to hist? eg: R> x <- rnorm(200) R> plot.new() R> hist(x, col = "blue", freq = FALSE) R> lines(density(x), col = "red", lwd = 2) Does that work? If not -- what if you use `dev.new()` in place of `plot.new()`? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
-- Best Regards, Reka.
Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
On 2011-05-23 21:31, Rekha wrote:
S . Am getting error still now if i use both version of the codes . i have to call any library?
Your code works fine for me, too, as it should. Have you perhaps redefined the hist() function? Do you get a histogram? The error you quote would result if you called lines() without opening a graphics device. Peter Ehlers
On Tue, May 24, 2011 at 9:22 AM, Steve Lianoglou< mailinglist.honeypot at gmail.com> wrote:
Hi, On Mon, May 23, 2011 at 11:41 PM, Rekha<chithralekha86 at gmail.com> wrote:
Hello All,* *I want to draw a histogram with density curve. * *For that simply i created a data called*"x" *and i used the function
called
* hist(x, col = "blue", freq = FALSE),** *from this function i got a histogram*. *After that , i tried this function* ** lines(density(x), col = "red",
lwd
= 2 ) *but i could not get the density curve. So, Again i used other function* curve(dnorm, col = 2, add = TRUE)** *instead of the previous function for density curve. but still am getting error in R like this: Error in plot.xy(xy.coords(x, y), type = type, ...) plot.new has not been called yet" * I have used below codes to have a data and histogram with density
curve"
x<- rnorm(200) hist(x, col = "blue", freq = FALSE) lines(density(x), col = "red", lwd = 2)
You should use the code above. I don't get it though -- this is working fine for me. Are you getting the "plot.new" error for both versions of your code? Although I feel like in 99% of the time this won't be necessary, but what happens if you call `plot.new()` before your call to hist? eg: R> x<- rnorm(200) R> plot.new() R> hist(x, col = "blue", freq = FALSE) R> lines(density(x), col = "red", lwd = 2) Does that work? If not -- what if you use `dev.new()` in place of `plot.new()`? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact