Hello, It seems that there is a problem when plotting an expression in the ylab of a plot in case it is too long. Example: plot(1) title(ylab = "test looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong ") # work plot(1) title(ylab = expression(paste("test (% of 360" *degree, ")"))) # works plot(1) title(ylab = expression(paste("test looooooooooooooooooooooooooong (% of 360" *degree, ")"))) # doesn't work (R version R 2.11.1, on win 7 ) Is it supposed to be this way? (shouldn't there be at least a warning ?) Best, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]]
Barry Rowlingson
2010-Sep-28 09:29 UTC
[R] A problem with plotting a long expression in ylab ?
On Tue, Sep 28, 2010 at 10:03 AM, Tal Galili <tal.galili at gmail.com> wrote:> Hello, > > It seems that there is a problem when plotting an expression in the ylab of > a plot in case it is too long. > > Example: > > plot(1) > title(ylab = "test > looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong > ") # work > plot(1) > title(ylab = expression(paste("test (% of 360" *degree, ")"))) # works > plot(1) > title(ylab = expression(paste("test looooooooooooooooooooooooooong (% of > 360" *degree, ")"))) # doesn't workwhat does 'work/doesn't work' mean? I see some problems with the appearance of the label, and they seem related to the line breaks in the label. A single line label: > plot(1) > title(ylab="looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong cat is looooooooooooooooooooooooooooooooooooooooooooooooong") (where any line breaks you see are due to mail clients linebreaking) works fine (except of course the label is truncated at the start and end). However if I do: > plot(1) > title(ylab="looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong cat is\n looooooooooooooooooooooooooooooooooooooooooooooooong") (with a newline char \n in there) I only see the last "looo*oong" because the first line is out of my margin area. I can actually see the descender of the 'g', so I know it's there. I think the 'doesn't work' you are having is because there's a newline on the end of your continuation string: > plot(1) > title(ylab="foo + ") # has a newline at end > title(ylab="foo") # doesn't You can give more label space by using par(mar=, for example:> par(mar=c(5,8,4,2)) > plot(1) > title(ylab="long\ncat\nis\nlong")But of course you need to know how many lines your ylab will be before you make the plot... Barry