Split graph labels in 2 levels

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Split graph labels in 2 levels

Andrej Kastrin
Dear R users,

is there any simple low-level function that split "single-line" graph
labels and produce something like (e.g. for x axis):

100    300    500   700...
     200    400   600

Cheers, Andrej

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: Split graph labels in 2 levels

Marc Schwartz (via MN)
On Thu, 2005-12-29 at 14:49 +0100, Andrej Kastrin wrote:
> Dear R users,
>
> is there any simple low-level function that split "single-line" graph
> labels and produce something like (e.g. for x axis):
>
> 100    300    500   700...
>      200    400   600
>
> Cheers, Andrej

You could do something like this:

 # Draw some points
 # Do not plot the x axis
 plot(rnorm(1000), xaxt = "n")

 # Now create the x axis labels, using "\n" for the odd values
 # This puts the following even values one line below
 x.lab <- paste(seq(0, 1000, 100), c("", "\n"), sep = "")

 # Now do the axis, but tickmarks only
 axis(1, at = seq(0, 1000, 100), labels = NA)

 # Now do the labels
 mtext(1, at = seq(0, 1000, 100), text = x.lab, line = 2)


See ?axis, ?paste and ?mtext for more information.

You might also want to look at R FAQ 7.27 on rotating axis labels,
depending upon your requirements.

HTH,

Marc Schwartz

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: Split graph labels in 2 levels

P Ehlers


Marc Schwartz wrote:

> On Thu, 2005-12-29 at 14:49 +0100, Andrej Kastrin wrote:
>
>>Dear R users,
>>
>>is there any simple low-level function that split "single-line" graph
>>labels and produce something like (e.g. for x axis):
>>
>>100    300    500   700...
>>     200    400   600
>>
>>Cheers, Andrej
>
>
> You could do something like this:
>
>  # Draw some points
>  # Do not plot the x axis
>  plot(rnorm(1000), xaxt = "n")
>
>  # Now create the x axis labels, using "\n" for the odd values
>  # This puts the following even values one line below
>  x.lab <- paste(seq(0, 1000, 100), c("", "\n"), sep = "")
>
>  # Now do the axis, but tickmarks only
>  axis(1, at = seq(0, 1000, 100), labels = NA)
>
>  # Now do the labels
>  mtext(1, at = seq(0, 1000, 100), text = x.lab, line = 2)
>
>
> See ?axis, ?paste and ?mtext for more information.
>

Another way is to use the padj argument to axis:

   plot(rnorm(1000), xaxt = "n")
   axis(1, at = seq(0, 1000, 100), padj = c(0, 1))

Adjust padj to suit your needs; e.g. padj = c(1, -0.2)

Peter Ehlers


> You might also want to look at R FAQ 7.27 on rotating axis labels,
> depending upon your requirements.
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> [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

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: Split graph labels in 2 levels

Jim Lemon-2
In reply to this post by Andrej Kastrin
Andrej Kastrin wrote:
> Dear R users,
>
> is there any simple low-level function that split "single-line" graph
> labels and produce something like (e.g. for x axis):
>
> 100    300    500   700...
>      200    400   600
>
staxlab in the plotrix package.

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