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:juli at ceam.es http://www.gva.es/ceam GCTE Fire Network - http://www.gva.es/ceam/FireNetwork
"juli g. pausas" <juli at ceam.es> 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 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
>>>>> "juli" == juli g pausas <juli at ceam.es> >>>>> 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