Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate 180 degrees an mtext() in R

Tags:

plot

r

Apparently, mtext() in R doesn't support the srt parameter whose job is to rotate a piece of text.

I need mtext() to create an axis title on side 4 of my moving plot (i.e., values to be plotted come from a function so they change and so do the plot axes values). I was wondering then, what options do I have to rotate 180 degrees this side 4 axis title?

An example is BELOW:

curve(dnorm(x),-3,3)
mtext("Strength",side=4,srt=180)
like image 535
rnorouzian Avatar asked Feb 03 '17 23:02

rnorouzian


1 Answers

You can use par("usr") to obtain extremes of the plot area and use it to place your text without having to explicitly specify the x and y.

Try

curve(dnorm(x),-3,3)
corners = par("usr") #Gets the four corners of plot area (x1, x2, y1, y2)
par(xpd = TRUE) #Draw outside plot area
text(x = corners[2]+.5, y = mean(corners[3:4]), "Strength", srt = 270)

This way it will always be on the right extreme and vertically in the middle.

like image 139
d.b Avatar answered Oct 14 '22 23:10

d.b