Dear All: I plotted a histogram with Abline, clipping with color codes but i run into some problems. The "abline' does not show up at all, and when i request the 'prob=True' (to obtain the freqs), my clipped region colors the section of the graph instead of the plot only. Is there any way i can get the y-axis figures to be in whole numbers rather than decimals? Many thanks for your help. YA Here are the working codes i am tweaking. Everything worked fine before i trying adding stuffs (prob=T, etc). x <- rnorm(1000) hist(x, xlim=c(-4,4),ylab="Prevalence",prob=T,lwd=3,las=1) lines(density(x),col="black",lwd=2) usr <- par("usr") clip(usr[1], -2, usr[3], usr[4]) hist(x, col = 'red', add = TRUE) clip(2, usr[2], usr[3], usr[4]) hist(x, col = 'blue', add = TRUE) abline(v=c(-1),lty=1,lwd=3,col="black") do.call("clip", as.list(usr)) # reset to plot region -- View this message in context: http://r.789695.n4.nabble.com/Histogram-plot-help-tp4651958.html Sent from the R help mailing list archive at Nabble.com.
Hello, I can't say I understand your graph but as for the abline not showing up, it's outside the clipped region so it shouldn't. If you want it to show up, in the previous line, and after the hist() call, include clip(2, -2, usr[3], usr[4]) As for the decimals, those are normal, have you seen the data you're ploting? To have whole numbers use the arguments ylim and yaxt = "n" in the first call to hist and axis(2, ...) afterward. Something like hist(x, xlim=c(-4,4),ylab="Prevalence",prob=T,lwd=3,las=1, ylim = c(0, 3), yaxt="n") axis(2, at = 0:3) Oh, and you forgot prob = TRUE in the other calls to hist(). Hope this helps, Rui Barradas Em 03-12-2012 22:21, YAddo escreveu:> Dear All: > > I plotted a histogram with Abline, clipping with color codes but i run into > some problems. The "abline' does not show up at all, and when i request > the 'prob=True' (to obtain the freqs), my clipped region colors the section > of the graph instead of the plot only. > > Is there any way i can get the y-axis figures to be in whole numbers rather > than decimals? > > Many thanks for your help. > YA > > Here are the working codes i am tweaking. > > Everything worked fine before i trying adding stuffs (prob=T, etc). > > > x <- rnorm(1000) > hist(x, xlim=c(-4,4),ylab="Prevalence",prob=T,lwd=3,las=1) > lines(density(x),col="black",lwd=2) > usr <- par("usr") > clip(usr[1], -2, usr[3], usr[4]) > hist(x, col = 'red', add = TRUE) > clip(2, usr[2], usr[3], usr[4]) > hist(x, col = 'blue', add = TRUE) > abline(v=c(-1),lty=1,lwd=3,col="black") > do.call("clip", as.list(usr)) # reset to plot region > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Histogram-plot-help-tp4651958.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
Does it work the way you want if you add prob=TRUE to the second and third hist() commands and run do.call() before abline()? ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of YAddo > Sent: Monday, December 03, 2012 4:22 PM > To: r-help at r-project.org > Subject: [R] Histogram plot help > > Dear All: > > I plotted a histogram with Abline, clipping with color codes but i run > into > some problems. The "abline' does not show up at all, and when i > request > the 'prob=True' (to obtain the freqs), my clipped region colors the > section > of the graph instead of the plot only. > > Is there any way i can get the y-axis figures to be in whole numbers > rather > than decimals? > > Many thanks for your help. > YA > > Here are the working codes i am tweaking. > > Everything worked fine before i trying adding stuffs (prob=T, etc). > > > x <- rnorm(1000) > hist(x, xlim=c(-4,4),ylab="Prevalence",prob=T,lwd=3,las=1) > lines(density(x),col="black",lwd=2) > usr <- par("usr") > clip(usr[1], -2, usr[3], usr[4]) > hist(x, col = 'red', add = TRUE) > clip(2, usr[2], usr[3], usr[4]) > hist(x, col = 'blue', add = TRUE) > abline(v=c(-1),lty=1,lwd=3,col="black") > do.call("clip", as.list(usr)) # reset to plot region > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Histogram- > plot-help-tp4651958.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.