Home > Enterprise >  How to rotate ylab in basic plot R
How to rotate ylab in basic plot R

Time:11-30

I've created three plots, I want to set the ylab text on the top and rotate text in ylab = "text", but I can't do it using text, or par("usr") and draw a new axis. How to do it?

steps1 <- c(77:82)
steps2 <- c(72:82)
steps3 <- c(62:82)
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3))
par(las = 1)
plot(steps1, dfL1_F[77:82],
type= "o",pch=16, lty=1, col="black", xlab = 'Step finals', ylab = 'Max F, A.U.')
abline(h=c(0.000450), lwd=1.5, lty=2, col="red")
grid(nx = NULL, ny = NULL,lty = 2, col = "gray", lwd = 1)
plot(steps2, dfL1_F[72:82],
type= "o",pch=16, lty=1, col="black", xlab = 'Step finals', ylab = 'Max F, A.U.')
grid(nx = NULL, ny = NULL,lty = 2, col = "gray", lwd = 1)
abline(h=c(0.000450), lwd=1.5, lty=2, col="red") 
plot(steps3, dfL1_F[62:82],
type= "o",pch=16, lty=1, col="black", xlab = 'Step finals', ylab = 'Max F, A.U.')
grid(nx = NULL, ny = NULL,lty = 2, col = "gray", lwd = 1)
abline(h=c(0.000450), lwd=1.5, lty=2, col="red")   
par(opar)

Sorry, for trouble, this is input data:

c(0.090803, 0.053571, 0.059279, 0.081256, 0.898884, 0.046667, 0.036066, 
0.024925, 0.109469, 0.030897, 0.052733, 0.013766, 0.012801, 
0.012609, 0.009315, 0.015449, 0.031633, 0.009842, 0.014112, 0.016614, 
0.006702, 0.006865, 0.007912, 0.023806, 0.023373, 0.009024, 0.008952, 
0.042152, 0.010782, 0.006892, 0.006798, 0.006797, 0.006586, 0.020231, 
0.040914, 0.007164, 0.008807, 0.004308, 0.009495, 0.008776, 0.006001, 
0.004247, 0.052963, 0.006756, 0.02555, 0.002508, 0.003779, 0.00453, 
0.003253, 0.006861, 0.009106, 0.001776, 0.004892, 0.005216, 0.010059, 
0.0045, 0.003041, 0.005896, 0.00287, 0.003333, 0.008464, 0.003295, 
0.002963, 0.001889, 0.0021, 0.001508, 0.002127, 0.001287, 0.001515, 
0.001391, 0.002729, 0.002551, 0.001971, 0.001635, 0.000612, 0.00097, 
0.000504, 3e-04, 0.000385, 0.000322, 0.000111, 0.000111)

CodePudding user response:

You can remove the ylab and create an adjustable ylab using mtext Using mtext you can move the title left and right using adj, move the title up and down using padj, and change the size of the font using cex. You may have to play with padj and adj a bit to get the label in the right position for your needs

steps1 <- c(77:82)
steps2 <- c(72:82)
steps3 <- c(62:82)
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3))
par(las = 1)
plot(steps1, dfL1_F[77:82],
     type= "o",pch=16, lty=1, col="black", xlab = 'Step finals', ylab = '')
abline(h=c(0.000450), lwd=1.5, lty=2, col="red")
#adj will move the title left and right and padj moves the title up and down
mtext("MAX F", col = "black", adj=-0.4, padj=-1, cex=0.6)
grid(nx = NULL, ny = NULL,lty = 2, col = "gray", lwd = 1)
plot(steps2, dfL1_F[72:82],
     type= "o",pch=16, lty=1, col="black", xlab = 'Step finals', ylab = '')
#adj will move the title left and right and padj moves the title up and down
mtext("MAX F.", col = "black", adj=-0.4, padj=-1, cex=0.6)
grid(nx = NULL, ny = NULL,lty = 2, col = "gray", lwd = 1)
abline(h=c(0.000450), lwd=1.5, lty=2, col="red") 
plot(steps3, dfL1_F[62:82],
     type= "o",pch=16, lty=1, col="black", xlab = 'Step finals', ylab = '')
#adj will move the title left and right and padj moves the title up and down
mtext("MAX F", col = "black", adj=-0.4, padj=-1, cex=0.6)
grid(nx = NULL, ny = NULL,lty = 2, col = "gray", lwd = 1)
abline(h=c(0.000450), lwd=1.5, lty=2, col="red")   
par(opar)

example1

  •  Tags:  
  • r
  • Related