[R] barplot plot together
Dear colleges, I'm trying to combine a barplot and a plot in a single figure as follows: data - 1:6 t - barplot(data, axes=F) par(new= T) plot(t, data, type=b) However, as you can see in the example, the dots of the second plot do not fall in the midpoint of the bars in the first. Any trick for setting the 2 plots at the same scale? I have unsuccessfully tried: plot(t, data, type=b, xlim=c(0,7)) plot(t, data, type=b, xlim=c(min(t),max(t))) (R 1.8.1, for Windows) Thanks Juli -- Juli G. Pausas Centro de Estudios Ambientales del Mediterraneo (CEAM) C/ Charles R. Darwin 14, Parc Tecnologic, 46980 Paterna, Valencia, SPAIN Tel: (+ 34) 96 131 8227; Fax: (+ 34) 96 131 8190 mailto:[EMAIL PROTECTED] http://www.gva.es/ceam GCTE Fire Network - http://www.gva.es/ceam/FireNetwork __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] barplot plot together
juli == juli g pausas [EMAIL PROTECTED] on Thu, 18 Dec 2003 10:54:08 +0100 writes: juli Dear colleges, juli I'm trying to combine a barplot and a plot in a single figure as follows: juli data - 1:6 juli t - barplot(data, axes=F) juli par(new= T) juli plot(t, data, type=b) juli However, as you can see in the example, the dots of juli the second plot do not fall in the midpoint of the juli bars in the first. Any trick for setting the 2 plots juli at the same scale? yes, use bd - barplot(data) points(bd, data, type = b) instead. A general recommendation: Try to *not* use par(new = TRUE) if you can. Martin __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] barplot plot together
juli g. pausas [EMAIL PROTECTED] writes: Dear colleges, I'm trying to combine a barplot and a plot in a single figure as follows: data - 1:6 t - barplot(data, axes=F) par(new= T) plot(t, data, type=b) However, as you can see in the example, the dots of the second plot do not fall in the midpoint of the bars in the first. Any trick for setting the 2 plots at the same scale? I have unsuccessfully tried: plot(t, data, type=b, xlim=c(0,7)) plot(t, data, type=b, xlim=c(min(t),max(t))) (R 1.8.1, for Windows) The canonical trick for getting two plots on the same scale is to set xlim (and ylim) on *both*. On barplots, this gets a bit tricky since you have to leave room for the column width (the actual calculation can be read inside barplot.default). However, I'd try for something like t - barplot(data,names=1:6,ylim=range(c(0,data*1.01))) points(t, data, type=b) -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] barplot plot together
Thank you very much! I'm using par(new = TRUE) because in my real case, the 2 plots have different ylim (different y-scale). I got what I wanted by using the same xlim in the barplot and in the plot, as suggested by Peter. My real case: par(mar= c(7, 4, 5, 5) + 0.1) area - c(136, 3426, 5594, 29268, 19080, 31461, 72629, 225443)/ 1 nfires - c(48, 134, 80, 131, 27, 24, 23, 14) t - barplot(area, xlim=c(0.5,9.5), ylim=c(0, 25), ylab=Area burnt (x 1000 ha), xlab=Fire size class) box() par(new= T, yaxs = i, xpd=TRUE) plot(t, nfires, type=o, xlim=c(0.5,9.5), pch=19, ylim=c(0, 140), axes=F, xlab=, ylab=) axis(4); mtext(Number of fires, side=4, line=3, col=1) legend(2, 155, Number, lty= 1, pch= 19, bty=n, cex=0.8) legend(2, 163, Area, fill= 2, bty=n, cex=0.8) Cheers Juli Martin Maechler wrote: juli == juli g pausas [EMAIL PROTECTED] on Thu, 18 Dec 2003 10:54:08 +0100 writes: juli Dear colleges, juli I'm trying to combine a barplot and a plot in a single figure as follows: juli data - 1:6 juli t - barplot(data, axes=F) juli par(new= T) juli plot(t, data, type=b) juli However, as you can see in the example, the dots of juli the second plot do not fall in the midpoint of the juli bars in the first. Any trick for setting the 2 plots juli at the same scale? yes, use bd - barplot(data) points(bd, data, type = b) instead. A general recommendation: Try to *not* use par(new = TRUE) if you can. Martin -- Juli G. Pausas Centro de Estudios Ambientales del Mediterraneo (CEAM) C/ Charles R. Darwin 14, Parc Tecnologic, 46980 Paterna, Valencia, SPAIN Tel: (+ 34) 96 131 8227; Fax: (+ 34) 96 131 8190 mailto:[EMAIL PROTECTED] http://www.gva.es/ceam GCTE Fire Network - http://www.gva.es/ceam/FireNetwork [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help