[R] Barplot + plot same scale

Samuel Dennis sjdennis3 at gmail.com
Thu Jan 7 22:39:56 CET 2010


Forget about two separate plots overlaid on each other. You are far
better off using the lines function I expect.

To obtain the centres of the bars for plotting, you need to record the
output of the barplot as a variable and use that in your line graph.
Try the following code:

midpts <- barplot(c(10,12,18))
lines(midpts,c(0,2,3), t="l")

This will make your barplot, save the centres of the bars to a
variable called "midpts", and then plot a line over those bars.

I hope this helps.

Samuel Dennis


2010/1/8 Mister Vanhalen <mistervanhalen at gmail.com>:
> Hello,
>
> I would like to plot :
>
> barplot(c(10,12,18))
>
> and
>
> plot(c(0,2,3), t="l")
>
> and many other plots...
>
> in a same scale. With par(new=T) it's not align, points are not in the
> middle of the bar of barplot. Is there an easely solution to align that ?
>
> Thank for you help,
>
> G
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list