0

I have this plot with a really long label along the y axis using 'expression', however, it gets distorted when I try to break it into two lines, see below:

year = seq(1980,1990)
irrig.area = seq(1,11)
ylab.text = expression("This label is really long label but is  " ~ "" <= 100 ~ "characters in total 
length")
plot(year,irrig.area,xlab="Year",ylab=ylab.text)

The label is really long but works as expected with 'expression'

enter image description here

By trying to add a new line like so:

ylab.text = expression("This label is really\n long label but is  " ~ "" <= 100 ~ "characters in 
total length")
plot(year,irrig.area,xlab="Year",ylab=ylab.text)

My y axis label gets cut off. What am I doing wrong?

enter image description here

Salvador
  • 979
  • 1
  • 8
  • 14
  • The whole `?plotmath` stuff that uses expressions doesn't allow for newline characters. See other options in linked duplicate question. – MrFlick Jan 21 '20 at 19:05
  • Those questions pertain to titles only, my questions is about y axis labels. Any of those solutions don't work for axis labels. – Salvador Jan 21 '20 at 19:18
  • The plotting for the title is the same as the axis labels. Just make sure to add enough room in the margin for the extra text. For example running `par(mar=c(5,6,4,2)+.1)` before the plot (the 6 is larger than the default 4 for the left margin) – MrFlick Jan 21 '20 at 19:23
  • Ok..thanks, will try that ... – Salvador Jan 21 '20 at 19:44
  • I tried:par(mar=c(5,6,4,2)+.1) plot(year,irrig.area,xlab="Year",ylab=ylab.text) but still does not work well. It breaks the lines but the second line continues where the first line ends. I see that this is closed, should I reopen? – Salvador Jan 21 '20 at 20:44
  • If you want it centered, use `atop()` as described in the duplicates. – MrFlick Jan 21 '20 at 20:52
  • par(mar=c(5,6,4,2)+.1) ylab.text = expression(atop("This label is really long label but is\n " ~ "" <= 100 ~ "characters in total length")) plot(year,irrig.area,xlab="Year",ylab=ylab.text) does not work either. atop doesn't seem to have any effect here. I will put it to rest I think. Thanks for checking into it. – Salvador Jan 21 '20 at 21:28
  • No, you need to split up the top and bottom part for the `atop` to work. Did you read the suggestions in the duplicate? You can't use `\n` for nice line wrapping with `plotmath` – MrFlick Jan 21 '20 at 21:36

0 Answers0