X-axis labels not displayed when changing ylim

4 messages Options
Embed this post
Permalink
Sarah Bonnin

X-axis labels not displayed when changing ylim

Reply Threaded More More options
Print post
Permalink
Dear R users,

I am encountering a x axis labeling problem on quite basic plots...
I use the following code which displays the labels on the x-axis with a
45 degrees angle:

p <- plot(myobject1, type="b", col="red",cex=1, lwd=2, axes=FALSE,
ann=FALSE, ylim=c(0,70))
title(main="title", font.main=4)
axis(side=1, lab=F)
text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,labels=mylabels,xpd=T,
cex=0.8, font=2)
axis(side=2, las=1, cex.axis=0.8, font=2)

I set up the ylim from 0 to 70 for plotting that object "myobject1" ->
works well.
However, when i try to use the same script with another set of data
"myobject2" (same number of points, same labels, but different
values...) that ranges from 0 to 2 (ylim changed to "c(0,2)"), the
labels on the x axis disappear...
When i try to run the same lines for "myobject2" but putting the ylim
higher "c(0,50)", the labels on the x axis are displayed.

I picked up some pieces of code here and there so i may do an obvious
mistake but cannot figure out what it is! I tried to modify the text
parameters "adj" or "par("usr")...", unsuccessfully...
I hope i made it clear, there must be a scaling problem that i really
don't get...
I run R 2.8.0 under Windows XP Pro.

Thank you for your help!

Sarah

______________________________________________
[hidden email] 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.
Patrick Connolly-4

Re: X-axis labels not displayed when changing ylim

Reply Threaded More More options
Print post
Permalink
On Thu, 09-Jul-2009 at 05:36PM +0200, Sarah Bonnin wrote:

> Dear R users,
>
> I am encountering a x axis labeling problem on quite basic plots...
> I use the following code which displays the labels on the x-axis with a  
> 45 degrees angle:
>
> p <- plot(myobject1, type="b", col="red",cex=1, lwd=2, axes=FALSE,  
> ann=FALSE, ylim=c(0,70))
> title(main="title", font.main=4)
> axis(side=1, lab=F)
> text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,labels=mylabels,xpd=T,  

I think this part is what's not transferable to a smaller range of
y-values.

par("usr")[3] will be much smaller when ylim goes to only 2 instead of
70.  Subtract 2 from that, and you have a very different kettle of
fish.

Without knowing anything about myobject1 and myobject2 I could be
completely ooff the mark, of cours.

HTH





> cex=0.8, font=2)
> axis(side=2, las=1, cex.axis=0.8, font=2)
>
> I set up the ylim from 0 to 70 for plotting that object "myobject1" ->  
> works well.
> However, when i try to use the same script with another set of data  
> "myobject2" (same number of points, same labels, but different  
> values...) that ranges from 0 to 2 (ylim changed to "c(0,2)"), the  
> labels on the x axis disappear...
> When i try to run the same lines for "myobject2" but putting the ylim  
> higher "c(0,50)", the labels on the x axis are displayed.
>
> I picked up some pieces of code here and there so i may do an obvious  
> mistake but cannot figure out what it is! I tried to modify the text  
> parameters "adj" or "par("usr")...", unsuccessfully...
> I hope i made it clear, there must be a scaling problem that i really  
> don't get...
> I run R 2.8.0 under Windows XP Pro.
>
> Thank you for your help!
>
> Sarah
>
> ______________________________________________
> [hidden email] 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.

--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.  
   ___    Patrick Connolly  
 {~._.~}                   Great minds discuss ideas    
 _( Y )_           Average minds discuss events
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)                        ..... Eleanor Roosevelt
         
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

______________________________________________
[hidden email] 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.
Sarah Bonnin

Re: X-axis labels not displayed when changing ylim

Reply Threaded More More options
Print post
Permalink
That made the deal, i tried to change a bunch of parameters before but i am not yet familiar enough with the par("usr") one...
Thank you very much!


-----Mensaje original-----
De: Patrick Connolly [mailto:[hidden email]]
Enviado el: jue 09/07/2009 22:36
Para: Sarah Bonnin
CC: [hidden email]
Asunto: Re: [R] X-axis labels not displayed when changing ylim
 
On Thu, 09-Jul-2009 at 05:36PM +0200, Sarah Bonnin wrote:

> Dear R users,
>
> I am encountering a x axis labeling problem on quite basic plots...
> I use the following code which displays the labels on the x-axis with a  
> 45 degrees angle:
>
> p <- plot(myobject1, type="b", col="red",cex=1, lwd=2, axes=FALSE,  
> ann=FALSE, ylim=c(0,70))
> title(main="title", font.main=4)
> axis(side=1, lab=F)
> text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,labels=mylabels,xpd=T,  

I think this part is what's not transferable to a smaller range of
y-values.

par("usr")[3] will be much smaller when ylim goes to only 2 instead of
70.  Subtract 2 from that, and you have a very different kettle of
fish.

Without knowing anything about myobject1 and myobject2 I could be
completely ooff the mark, of cours.

HTH





> cex=0.8, font=2)
> axis(side=2, las=1, cex.axis=0.8, font=2)
>
> I set up the ylim from 0 to 70 for plotting that object "myobject1" ->  
> works well.
> However, when i try to use the same script with another set of data  
> "myobject2" (same number of points, same labels, but different  
> values...) that ranges from 0 to 2 (ylim changed to "c(0,2)"), the  
> labels on the x axis disappear...
> When i try to run the same lines for "myobject2" but putting the ylim  
> higher "c(0,50)", the labels on the x axis are displayed.
>
> I picked up some pieces of code here and there so i may do an obvious  
> mistake but cannot figure out what it is! I tried to modify the text  
> parameters "adj" or "par("usr")...", unsuccessfully...
> I hope i made it clear, there must be a scaling problem that i really  
> don't get...
> I run R 2.8.0 under Windows XP Pro.
>
> Thank you for your help!
>
> Sarah
>
> ______________________________________________
> [hidden email] 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.

--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.  
   ___    Patrick Connolly  
 {~._.~}                   Great minds discuss ideas    
 _( Y )_           Average minds discuss events
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)                        ..... Eleanor Roosevelt
         
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Jim Lemon

Re: X-axis labels not displayed when changing ylim

Reply Threaded More More options
Print post
Permalink
In reply to this post by Sarah Bonnin
Sarah Bonnin wrote:

> Dear R users,
>
> I am encountering a x axis labeling problem on quite basic plots...
> I use the following code which displays the labels on the x-axis with
> a 45 degrees angle:
>
> p <- plot(myobject1, type="b", col="red",cex=1, lwd=2, axes=FALSE,
> ann=FALSE, ylim=c(0,70))
> title(main="title", font.main=4)
> axis(side=1, lab=F)
> text(axTicks(1), par("usr")[3] - 2, srt=45,
> adj=1,labels=mylabels,xpd=T, cex=0.8, font=2)
> axis(side=2, las=1, cex.axis=0.8, font=2)
>
> I set up the ylim from 0 to 70 for plotting that object "myobject1" ->
> works well.
> However, when i try to use the same script with another set of data
> "myobject2" (same number of points, same labels, but different
> values...) that ranges from 0 to 2 (ylim changed to "c(0,2)"), the
> labels on the x axis disappear...
> When i try to run the same lines for "myobject2" but putting the ylim
> higher "c(0,50)", the labels on the x axis are displayed.
>
> I picked up some pieces of code here and there so i may do an obvious
> mistake but cannot figure out what it is! I tried to modify the text
> parameters "adj" or "par("usr")...", unsuccessfully...
> I hope i made it clear, there must be a scaling problem that i really
> don't get...
> I run R 2.8.0 under Windows XP Pro.
Hi Sarah,
Try this:

p <- plot(myobject2, type="b", col="red",cex=1, lwd=2, axes=FALSE,
ann=FALSE, ylim=c(0,2))
title(main="title", font.main=4)
axis(side=1, lab=F)
par(xpd=TRUE)
text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,labels=mylabels,xpd=T,
cex=0.8, font=2)
par(xpd=FALSE)
axis(side=2, las=1, cex.axis=0.8, font=2)

and see what happens.

Jim

______________________________________________
[hidden email] 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.