[R] axis: forcing last label to print

Shawn Polson polson at dbi.udel.edu
Sun Sep 20 16:16:55 CEST 2009


Thanks for the suggestion Jim,

A good thought, but unfortunately this doesn't quite work either:

-Since my example is log scale on that axis, the linearly spaced labels
still become to numerous near the end forcing the last label not to print

-Also, the labels don't print under the appropriate bars and since there are
now fewer labels than bars using the "at" command doesn't work properly
unless I specify a vector of locations which would essentially be manually
placing the labels for each graph I have to make (which is what I was trying
to get away from . . .)

Thanks,
Shawn


Jim Lemon-2 wrote:
> 
> On 09/20/2009 02:12 PM, Shawn Polson wrote:
>> Hello,
>>
>> I often use the axis command to add labels to axes with large numbers of
>> consecutively numbered names:
>>
>> y<- barplot (x, log="x")
>> axis(1, at = y, labels = c(1:12345))
>>
>> Since there are more labels than will fit in the space, the command only
>> prints selected labels.  This is what I want, except that it never
>> actually
>> prints a label for the final item.  Thus I end up with labels something
>> like
>> this:
>>
>> 1  16  123  1432  2134  3235  6578  11385
>>
>> when I really want the last label displayed to be the final category
>> number
>> (12345):
>>
>> 1  16  123  1432  2134  3235  6578   12345
>>
>> Short of manually choosing the labels, does anyone know a way to force
>> the
>> last category to be among those printed when axis selects labels?
>>
>>    
> Hi Shawn,
> You can get the first and last label with:
> 
> axis(1,seq(1,12345,length.out=8)
> 
> but you have to specify how many labels you want, and you will get 
> non-integer labels unless the upper limit divides evenly.
> 
> Jim
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/axis%3A-forcing-last-label-to-print-tp25527633p25530067.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list