Dear all, I'm trying to plot, in the same window, two different series, using barplot() for the first one and plot() for the second. What happens is that the second chart has a different axes origin, therefore the final plot is wrong. This piece of code shows the differences between the values of par()$usr: barplot(coredata(Z0), beside=TRUE, ylim=c(0,100)); par()$usr; par(new=T); plot(coredata(Z0), ylim=c(0,100)); par()$usr; I would like to know how it is possible to edit the values of par()$usr[3:4] of the second chart in order to be the same of the first one or, alternatively, how can I plot together bar and line series within the same reference system. Best Regards Guido Barbaglia
Axes Alignment Problem for Multiple Plots
7 messages · Barbaglia, Guido (ESA), John Kane, William Dunlap +1 more
What is Coredata(Z0)? It would be very useful. as the posting guidelines suggest to supply working code and sample data.
--- On Tue, 4/19/11, Barbaglia, Guido (ESA) <Guido.Barbaglia at fao.org> wrote:
From: Barbaglia, Guido (ESA) <Guido.Barbaglia at fao.org> Subject: [R] Axes Alignment Problem for Multiple Plots To: "r-help at r-project.org" <r-help at r-project.org> Cc: "Stigler, Matthieu (EST)" <Matthieu.Stigler at fao.org> Received: Tuesday, April 19, 2011, 11:42 AM Dear all, ???I'm trying to plot, in the same window, two different series, using barplot() for the first one and plot() for the second. What happens is that the second chart has a different axes origin, therefore the final plot is wrong. This piece of code shows the differences between the values of par()$usr: ???barplot(coredata(Z0), beside=TRUE, ylim=c(0,100)); ???par()$usr; ???par(new=T); ???plot(coredata(Z0), ylim=c(0,100)); ???par()$usr; I would like to know how it is possible to edit the values of par()$usr[3:4] of the second chart in order to be the same of the first one or, alternatively, how can I plot together bar and line series within the same reference system. Best Regards Guido Barbaglia
______________________________________________ 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.
Ok, I can replicate your problem, with following code:
dat <- 1:10
barplot(dat, beside=TRUE,ylim=c(0,100));
par()$usr;
par(new=T);
plot(dat, ylim=c(0,100), type="l");
par()$usr;
So it looks like even if you specify yourself ylim, the resulting
effective ylim (usr[3:4] ) will be different! More surprinsingly,
setting the usr parameter before is not effective:
par(new=T, usr=c(0,11,0,100));
this will not prevent par()$usr; to be different than fixed :-(
No idea, but hopefully someone else on the list will be able to provide
advice!
Matthieu
Le 19. 04. 11 20:47, John Kane a ?crit :
What is Coredata(Z0)? It would be very useful. as the posting guidelines suggest to supply working code and sample data. --- On Tue, 4/19/11, Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org> wrote:
From: Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org>
Subject: [R] Axes Alignment Problem for Multiple Plots
To: "r-help at r-project.org"<r-help at r-project.org>
Cc: "Stigler, Matthieu (EST)"<Matthieu.Stigler at fao.org>
Received: Tuesday, April 19, 2011, 11:42 AM
Dear all,
I'm trying to plot, in the same window,
two different series, using barplot() for the first one and
plot() for the second. What happens is that the second chart
has a different axes origin, therefore the final plot is
wrong. This piece of code shows the differences between the
values of par()$usr:
barplot(coredata(Z0), beside=TRUE,
ylim=c(0,100));
par()$usr;
par(new=T);
plot(coredata(Z0), ylim=c(0,100));
par()$usr;
I would like to know how it is possible to edit the values
of par()$usr[3:4] of the second chart in order to be the
same of the first one or, alternatively, how can I plot
together bar and line series within the same reference
system.
Best Regards
Guido Barbaglia
______________________________________________ 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.
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of mat
Sent: Tuesday, April 19, 2011 1:59 PM
To: John Kane
Cc: r-help at r-project.org
Subject: Re: [R] Axes Alignment Problem for Multiple Plots
Ok, I can replicate your problem, with following code:
dat <- 1:10
barplot(dat, beside=TRUE,ylim=c(0,100));
par()$usr;
par(new=T);
plot(dat, ylim=c(0,100), type="l");
par()$usr;
Use yaxs="i" (see ?par) to have plot use the desired
y limits verbatim.
However, usnig par(new=TRUE) is usually a bad way to
overlay things. Use lines() and points() when possible.
E.g.,
barCenters <- barplot(dat, beside=TRUE, ylim=c(0,12))
lines(x=barCenters, y=dat)
Note how the lines pass through the centers of the bar tops.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
So it looks like even if you specify yourself ylim, the resulting
effective ylim (usr[3:4] ) will be different! More surprinsingly,
setting the usr parameter before is not effective:
par(new=T, usr=c(0,11,0,100));
this will not prevent par()$usr; to be different than fixed :-(
No idea, but hopefully someone else on the list will be able
to provide
advice!
Matthieu
Le 19. 04. 11 20:47, John Kane a ?crit :
What is Coredata(Z0)? It would be very useful. as the posting guidelines suggest
to supply working code and sample data.
--- On Tue, 4/19/11, Barbaglia, Guido
(ESA)<Guido.Barbaglia at fao.org> wrote:
From: Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org>
Subject: [R] Axes Alignment Problem for Multiple Plots
To: "r-help at r-project.org"<r-help at r-project.org>
Cc: "Stigler, Matthieu (EST)"<Matthieu.Stigler at fao.org>
Received: Tuesday, April 19, 2011, 11:42 AM
Dear all,
I'm trying to plot, in the same window,
two different series, using barplot() for the first one and
plot() for the second. What happens is that the second chart
has a different axes origin, therefore the final plot is
wrong. This piece of code shows the differences between the
values of par()$usr:
barplot(coredata(Z0), beside=TRUE,
ylim=c(0,100));
par()$usr;
par(new=T);
plot(coredata(Z0), ylim=c(0,100));
par()$usr;
I would like to know how it is possible to edit the values
of par()$usr[3:4] of the second chart in order to be the
same of the first one or, alternatively, how can I plot
together bar and line series within the same reference
system.
Best Regards
Guido Barbaglia
______________________________________________ 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. ______________________________________________ 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.
Dear Matthieu, thanks for your clarification! Basically, what I need to do is to plot different series on the same chart using different types of plot (lines, barplot, ...) and it is fundamental that the various charts have the same reference system. I hope that someone in the list is able to fix my problem! Best Regards Guido Barbaglia
From: mat [matthieu.stigler at gmail.com]
Sent: 19 April 2011 22:58
To: John Kane
Cc: r-help at r-project.org; Barbaglia, Guido (ESA)
Subject: Re: [R] Axes Alignment Problem for Multiple Plots
Sent: 19 April 2011 22:58
To: John Kane
Cc: r-help at r-project.org; Barbaglia, Guido (ESA)
Subject: Re: [R] Axes Alignment Problem for Multiple Plots
Ok, I can replicate your problem, with following code:
dat <- 1:10
barplot(dat, beside=TRUE,ylim=c(0,100));
par()$usr;
par(new=T);
plot(dat, ylim=c(0,100), type="l");
par()$usr;
So it looks like even if you specify yourself ylim, the resulting
effective ylim (usr[3:4] ) will be different! More surprinsingly,
setting the usr parameter before is not effective:
par(new=T, usr=c(0,11,0,100));
this will not prevent par()$usr; to be different than fixed :-(
No idea, but hopefully someone else on the list will be able to provide
advice!
Matthieu
Le 19. 04. 11 20:47, John Kane a ?crit :
> What is Coredata(Z0)?
> It would be very useful. as the posting guidelines suggest to supply working code and sample data.
>
>
> --- On Tue, 4/19/11, Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org> wrote:
>
>> From: Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org>
>> Subject: [R] Axes Alignment Problem for Multiple Plots
>> To: "r-help at r-project.org"<r-help at r-project.org>
>> Cc: "Stigler, Matthieu (EST)"<Matthieu.Stigler at fao.org>
>> Received: Tuesday, April 19, 2011, 11:42 AM
>> Dear all,
>>
>> I'm trying to plot, in the same window,
>> two different series, using barplot() for the first one and
>> plot() for the second. What happens is that the second chart
>> has a different axes origin, therefore the final plot is
>> wrong. This piece of code shows the differences between the
>> values of par()$usr:
>>
>> barplot(coredata(Z0), beside=TRUE,
>> ylim=c(0,100));
>> par()$usr;
>> par(new=T);
>> plot(coredata(Z0), ylim=c(0,100));
>> par()$usr;
>>
>> I would like to know how it is possible to edit the values
>> of par()$usr[3:4] of the second chart in order to be the
>> same of the first one or, alternatively, how can I plot
>> together bar and line series within the same reference
>> system.
>>
>>
>> Best Regards
>> Guido Barbaglia
>> ______________________________________________
>> 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.
>>
Guido You missed William's e-mails, which solved the problem: use yaxs="i" in second call. Also, William made the good point that you can rather just use lines() in second call. Good William! Mat Le 20/04/2011 08:00, Barbaglia, Guido (ESA) a ?crit :
Dear Matthieu,
thanks for your clarification! Basically, what I need to do is to plot different series on the same chart using different types of plot (lines, barplot, ...) and it is fundamental that the various charts have the same reference system. I hope that someone in the list is able to fix my problem!
Best Regards
Guido Barbaglia
________________________________________
From: mat [matthieu.stigler at gmail.com]
Sent: 19 April 2011 22:58
To: John Kane
Cc: r-help at r-project.org; Barbaglia, Guido (ESA)
Subject: Re: [R] Axes Alignment Problem for Multiple Plots
Ok, I can replicate your problem, with following code:
dat<- 1:10
barplot(dat, beside=TRUE,ylim=c(0,100));
par()$usr;
par(new=T);
plot(dat, ylim=c(0,100), type="l");
par()$usr;
So it looks like even if you specify yourself ylim, the resulting
effective ylim (usr[3:4] ) will be different! More surprinsingly,
setting the usr parameter before is not effective:
par(new=T, usr=c(0,11,0,100));
this will not prevent par()$usr; to be different than fixed :-(
No idea, but hopefully someone else on the list will be able to provide
advice!
Matthieu
Le 19. 04. 11 20:47, John Kane a ?crit :
What is Coredata(Z0)?
It would be very useful. as the posting guidelines suggest to supply working code and sample data.
--- On Tue, 4/19/11, Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org> wrote:
From: Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org>
Subject: [R] Axes Alignment Problem for Multiple Plots
To: "r-help at r-project.org"<r-help at r-project.org>
Cc: "Stigler, Matthieu (EST)"<Matthieu.Stigler at fao.org>
Received: Tuesday, April 19, 2011, 11:42 AM
Dear all,
I'm trying to plot, in the same window,
two different series, using barplot() for the first one and
plot() for the second. What happens is that the second chart
has a different axes origin, therefore the final plot is
wrong. This piece of code shows the differences between the
values of par()$usr:
barplot(coredata(Z0), beside=TRUE,
ylim=c(0,100));
par()$usr;
par(new=T);
plot(coredata(Z0), ylim=c(0,100));
par()$usr;
I would like to know how it is possible to edit the values
of par()$usr[3:4] of the second chart in order to be the
same of the first one or, alternatively, how can I plot
together bar and line series within the same reference
system.
Best Regards
Guido Barbaglia
______________________________________________
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.
I've missed William's e-mail indeed, I've tested it and works great, thanks a lot!!! Many Thanks Guido
From: Matthieu Stigler [matthieu.stigler at gmail.com]
Sent: 20 April 2011 09:30
To: Barbaglia, Guido (ESA)
Cc: wdunlap at tibco.com; r-help at r-project.org
Subject: Re: [R] Axes Alignment Problem for Multiple Plots
Sent: 20 April 2011 09:30
To: Barbaglia, Guido (ESA)
Cc: wdunlap at tibco.com; r-help at r-project.org
Subject: Re: [R] Axes Alignment Problem for Multiple Plots
Guido You missed William's e-mails, which solved the problem: use yaxs="i" in second call. Also, William made the good point that you can rather just use lines() in second call. Good William! Mat Le 20/04/2011 08:00, Barbaglia, Guido (ESA) a ?crit : > Dear Matthieu, > > thanks for your clarification! Basically, what I need to do is to plot different series on the same chart using different types of plot (lines, barplot, ...) and it is fundamental that the various charts have the same reference system. I hope that someone in the list is able to fix my problem! > > > Best Regards > Guido Barbaglia > > ________________________________________ > From: mat [matthieu.stigler at gmail.com] > Sent: 19 April 2011 22:58 > To: John Kane > Cc: r-help at r-project.org; Barbaglia, Guido (ESA) > Subject: Re: [R] Axes Alignment Problem for Multiple Plots > > Ok, I can replicate your problem, with following code: > > dat<- 1:10 > barplot(dat, beside=TRUE,ylim=c(0,100)); > par()$usr; > par(new=T); > plot(dat, ylim=c(0,100), type="l"); > par()$usr; > > So it looks like even if you specify yourself ylim, the resulting > effective ylim (usr[3:4] ) will be different! More surprinsingly, > setting the usr parameter before is not effective: > par(new=T, usr=c(0,11,0,100)); > > this will not prevent par()$usr; to be different than fixed :-( > > No idea, but hopefully someone else on the list will be able to provide > advice! > > Matthieu > > > > > Le 19. 04. 11 20:47, John Kane a ?crit : >> What is Coredata(Z0)? >> It would be very useful. as the posting guidelines suggest to supply working code and sample data. >> >> >> --- On Tue, 4/19/11, Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org> wrote: >> >>> From: Barbaglia, Guido (ESA)<Guido.Barbaglia at fao.org> >>> Subject: [R] Axes Alignment Problem for Multiple Plots >>> To: "r-help at r-project.org"<r-help at r-project.org> >>> Cc: "Stigler, Matthieu (EST)"<Matthieu.Stigler at fao.org> >>> Received: Tuesday, April 19, 2011, 11:42 AM >>> Dear all, >>> >>> I'm trying to plot, in the same window, >>> two different series, using barplot() for the first one and >>> plot() for the second. What happens is that the second chart >>> has a different axes origin, therefore the final plot is >>> wrong. This piece of code shows the differences between the >>> values of par()$usr: >>> >>> barplot(coredata(Z0), beside=TRUE, >>> ylim=c(0,100)); >>> par()$usr; >>> par(new=T); >>> plot(coredata(Z0), ylim=c(0,100)); >>> par()$usr; >>> >>> I would like to know how it is possible to edit the values >>> of par()$usr[3:4] of the second chart in order to be the >>> same of the first one or, alternatively, how can I plot >>> together bar and line series within the same reference >>> system. >>> >>> >>> Best Regards >>> Guido Barbaglia >>> ______________________________________________ >>> 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. >>>