[R] barplot and line
Greg Snow
Greg.Snow at imail.org
Thu Apr 1 17:33:49 CEST 2010
Look at the 1st example on the help page for the updateusr function in the TeachingDemos package for a way to align a barplot and information added to it. See the axis function for creating your own custom axis.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Roslina Zakaria
> Sent: Wednesday, March 31, 2010 4:44 PM
> To: r-help at r-project.org
> Subject: [R] barplot and line
>
> Hi r-users,
>
> I have this data below and would like to plot a barplot overlap with a
> line.
> This is my data:
> > hist_50
> pdf_obs pdf_gen.50
> 1 0.000000 0.000000
> 2 0.083156 0.125366
> 3 0.132196 0.158230
> 4 0.126866 0.149432
> 5 0.120469 0.127897
> 6 0.121535 0.104096
> 7 0.103412 0.082171
> 8 0.082090 0.063539
> 9 0.065032 0.048408
> 10 0.050107 0.036470
> 11 0.036247 0.027236
> 12 0.031983 0.020198
> 13 0.017058 0.014893
> 14 0.009595 0.010928
> 15 0.007463 0.007986
> 16 0.006397 0.005816
> 17 0.003198 0.004222
> 18 0.003198 0.003057
> 19 0.000000 0.002208
>
> I tried
> sq <- seq(0,900,by=50)
> sq.50 <- as.character(sq)
> barplot(t(hist_50[,1]), col= "blue", beside=TRUE, ylim=c(0,0.2),
> main="Observed and generated gamma sum",
> xlab="Rainfall totals(mm)",cex.axis=0.8,ylab="Probability")
> legend("topright", c("observed","generated"), fill= c("blue","yellow"))
> rownames(hist_50) <- sq.50
> lines(spline(hist_50[,2]),lty=1)
>
> The problem is the x-axis label is invisible, I want 0, 50, 100,....
> Another thing is I want the line to plot on top of the barplot. It
> seems that it is shifted to the left.
>
> Thank you.
>
>
>
>
> [[alternative HTML version deleted]]
More information about the R-help
mailing list