Home > Net >  How to make y axis labels horizontal but keep y-axis title parallel?
How to make y axis labels horizontal but keep y-axis title parallel?

Time:03-07

I would like to make my y axis labels horizontal, while keeping my y axis titles as parallel. When I try inputting las=1 into the twoor.plot()argument, nothing happens. I have also tried ylas=1, y_las=1, lylas=1, rylas=1, and nothing happens. The only way I've been able to make my yaxis labels horizontal, is by using par(las=1), but then this makes my y-axis titles horizontal too, which I don't want...

This is my code so far:

  par(las=1)
    yFrequency <- c(0,20,40,60,80,100,120,140,160)
    GS_class_labels <- c("<2", "2-4", "4-8", "8-16", "16-32", "32-64", "64-128", "128<")
    twoord.plot(data=distribution,lx="Var1",ly="Freq", ry="cum_percentile",
                main="B1 Surface Grain Size Distribution",
                xlim=NULL,lylim=c(0,160),rylim=NULL,lwd=1.5,
                lcol=1,rcol=2,xlab="Grain Size (mm)",lytickpos=yFrequency, 
                ylab="Frequency",ylab.at=NA,
                rytickpos=NA,rylab="Percent Finer Than (%)",rylab.at=NA,
                lpch=1,rpch=2,
                type="b",xtickpos=NULL,xticklab=GS_class_labels,
                halfwidth=0.4,axislab.cex=1.1,
                do.first=NULL,xaxt="s", yticklab=yFrequency, cex.lab=1)

enter image description here

CodePudding user response:

An alternative way to set the y axis labels parallel is as follows. (1) Set both of the ylab and rylab from twoord.plot to empty. (2) Use mtext and set the parameters accordingly.

Here is the code to do that. Because you don't provide the distribution data, I use iris data just to make it possible to generate the plot.

# Emptying both of ylab and rylab

twoord.plot(data = iris,lx="Sepal.Length",ly="Petal.Width", ry="Sepal.Width",
            main="B1 Surface Grain Size Distribution",
            xlim=NULL,lylim=c(0,160),rylim=NULL,lwd=1.5,
            lcol=1,rcol=2,xlab="Grain Size (mm)",lytickpos=yFrequency, 
            ylab="",ylab.at=NA,
            rytickpos=NA,rylab="",rylab.at=NA,
            lpch=1,rpch=2,
            type="b",xtickpos=NULL,xticklab=GS_class_labels,
            halfwidth=0.4,axislab.cex=1.1,
            do.first=NULL,xaxt="n",yaxt="n", #yticklab=yFrequency, 
            cex.lab=1)

# Assign the previous labels of ylab and rylab to the *text* parameter of *mtext*. 
# side = 2 means the left side. side = 4 means the right side.
# las = 0 is the parallel style of the text. 
# line shows the distance of the text from the y axis. 

mtext(text = "Frequency", side = 2, las = 0, line = 2.5)
mtext(text = "Percent Finer Than (%)", side = 4, las = 0, line = 0.5)

The resulted plot:

enter image description here

  • Related