Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line y label in plot

Is there a way to create multi-line labels for the y axis in an R plot?

I have tried adding a \n where the newline should be, but then the first line of the label gets clipped:

l <- 10
plot(0:l, (0:l), type='l',
     yaxt='n',
     xlab='Index',
     ylab='Cumulative sum\nof the sorted weights')

Result of plot

This happens both with the tikzDevice and inside RStudio. Also, I tried some of the par() options with no luck. How to do it properly?

(The oversized uper margin bothers me, too...)

like image 827
krlmlr Avatar asked Dec 27 '22 00:12

krlmlr


1 Answers

You need to set the margins using mar or mgp:

l <- 10
op <- par(mar=c(5, 6, 4, 2) + 0.1)
plot(0:l, (0:l), type='l',
     yaxt='n',
     xlab='Index',
     ylab='Cumulative sum\nof the sorted weights')
par(op)

enter image description here

like image 100
smillig Avatar answered Jan 11 '23 10:01

smillig