简体   繁体   中英

How to modify the size of the x axis text in a twoord plot from the plotrix package?

I would like to make a twoord plot where I would like to decrease the size of the text on the x axis. So I am looking for the alternative to cex.axis. I tried using cexlab.axis but it changes the y axis values.I also tried to suppres the x axis altogether and then customise the x axis by specifying

    twoord.plot(lx=1:96, ly=mean_aod, rx=1:96, ry=tot_FCH,type=c("b","bar"),xaxt="n")
    axis(1, at = seq(1, 96, by = 1),srt=45, cex.axis=0.5)

But this doesn't get rid of the default labels plotted by twoord.plot. Basically I want the x axis labels to be from 1 to 96 at each of the 96 tick marks. The closest I have got to this is by specifying a variable month that runs from 1 to 96 and then running the code below.

   twoord.plot(lx=1:96, ly=mean_aod, rx=1:96, ry=tot_FCH,type=c("b","bar"), xticklab=month)

But the size of each label is too big and not all the labels are displayed. How can I rectify this? Many thanks in advance.

Looking at page(twoord.plot) we see that in twoord.plot when plot is called, argument axes is -already- set to FALSE and axes are built by calling axis . So, xaxt won't have any effect.

The thing is, though, that in the code is written: axis(1, ... **cex** = axilsab.cex . But setting cex in axis won't have the desired effect; cex.axis should be used instead. For axes 2 and 4, though, axilslab.cex argument is used by calling mtext . Eg mtext(axat, 2... cex = axislab.cex ; here cex (inside mtext ) has the desired effect.

Concluding, you can write a function twoord.plot2 where you change the cex argument to cex.axis when calling axis(1... . And then run your code by calling twoord.plot2 . Ie axis(1,... **cex.axis** = axislab.cex) .

EDIT

I will add a x_axislab.cex argument in the original twoord.plot in order to change only the size of x-axis' tickmarks:

Copy-paste everything from page(twoord.plot) in a text editor and name it twoord.plot2 . Then add an extra argument and change the body of the function:

twoord.plot2 <- #function (lx, ly, rx, ry, data = NULL, xlim = NULL, lylim = NULL, 
    #rylim = NULL, mar = c(5, 4, 4, 4), lcol = 1, rcol = 2, xlab = "", 
    #ylab = "", rylab = "", lpch = 1, rpch = 2, type = "b", xtickpos = NULL, 
    #xticklab = NULL, halfwidth = 0.4, axislab.cex = 1, 
   **x_axislab.cex = 1**, # do.first = NULL, 
   # ...)  #add argument `x_axislab.cex = 1` in the arguments of the original `twoord.plot`
#{
 #   if (!is.null(data)) {
 #       ly <- unlist(data[ly])

 #...everything else...

 #if (is.null(xticklab)) 
       axis(1, **cex.axis = x_axislab.cex**) #change here. it was **cex = axislab.cex**
  #  else {
 #if (is.null(xtickpos)) 
 #xtickpos <- 1:length(xticklab)
 #  if (is.null(xticklab)) 
  #     xticklab <- xtickpos
    axis(1, at = xtickpos, labels = xticklab, **cex.axis = x_axislab.cex**) #change here. it was **cex = axislab.cex**

 #.....everything else...

Then copy-paste your function in R and run something like:

twoord.plot2(...other arguments..., x_axislab.cex = 0.8)

to plot your data and change the size of x-axis' tickmarks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM