Rajarshi Guha
2004-Sep-07 17:52 UTC
[R] using text on the x axis ticks rather than numbers
Hello, is there a way in which I can use text labels rather than numbers on the x axis ticks? I basically have a vector of (say) 8 points and I want to plot these sequentially. Thus the x axis would have ticks at 1 .. 8. Rather than having the labels 1 .. 8 I would like to have some arbitrary text labels. Ideally I would like the labels to be rotated (say at 45 degrees) so that they don't overlap with each other. Is this possible? Thanks, ------------------------------------------------------------------- Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- Breadth-first search is the bulldozer of science. -- Randy Goebel
Hi! first supress axis drawing with param axes=FALSE in your plot function. The use axis function to add your axes. ?axis /E On Tue, 7 Sep 2004, Rajarshi Guha wrote:> Hello, > is there a way in which I can use text labels rather than numbers on > the x axis ticks? I basically have a vector of (say) 8 points and I want > to plot these sequentially. Thus the x axis would have ticks at 1 .. 8. > Rather than having the labels 1 .. 8 I would like to have some arbitrary > text labels. > > Ideally I would like the labels to be rotated (say at 45 degrees) so > that they don't overlap with each other. > > Is this possible? > > Thanks, > > ------------------------------------------------------------------- > Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> > GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE > ------------------------------------------------------------------- > Breadth-first search is the bulldozer of science. > -- Randy Goebel > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Marc Schwartz
2004-Sep-07 19:01 UTC
[R] using text on the x axis ticks rather than numbers
On Tue, 2004-09-07 at 12:52, Rajarshi Guha wrote:> Hello, > is there a way in which I can use text labels rather than numbers on > the x axis ticks? I basically have a vector of (say) 8 points and I want > to plot these sequentially. Thus the x axis would have ticks at 1 .. 8. > Rather than having the labels 1 .. 8 I would like to have some arbitrary > text labels. > > Ideally I would like the labels to be rotated (say at 45 degrees) so > that they don't overlap with each other. > > Is this possible? > > Thanks,Here is an example. For the axis labels, you need to use text() and not mtext() as the latter does not allow for text rotation: # Set margins to make room for x axis labels par(mar = c(7, 4, 4, 2) + 0.1) # Create plot with no x axis and no x axis label plot(1:8, xaxt = "n", xlab = "") # Set up x axis with tick marks alone axis(1, labels = FALSE) # Create arbitrary text labels <- paste("arbitrary text", 1:8, sep = " ") # plot x axis labels using: # par("usr")[3] - 0.25 as the vertical placement # srt = 45 as text rotation angle # adj = 1 to place right end of text at tick mark # xpd = TRUE to allow for text outside the plot region text(1:8, par("usr")[1] - 0.25, srt = 45, adj = 1, labels = labels, xpd = TRUE) # plot x axis label at line 6 (of 7) mtext(1, text = "X Axis Label", line = 6) You can adjust the value of the '0.25' offset as required to move the x axis labels up or down relative to the x axis. HTH, Marc Schwartz