Novartis / xgxr

R package for supporting exploratory graphics at http://opensource.nibr.com/xgx
Other
13 stars 7 forks source link

Consider adding code for rotating the y-axis label using the title. #60

Open iamstein opened 1 year ago

iamstein commented 1 year ago

From Andrew Wright

image

iamstein commented 1 year ago

Here's another way to do it. And actually, it just takes one command (theme), so maybe it's not worth a separate xgx function, though it might be easier to remember to type xgx_ylab_horiz("label") than the two lines it takes to call both ylab and remember all the theme/element code. It does scrunch the graph a little bit, but I think it's nicer than using the title option because it would be less confusing.

library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) + 
  geom_point() + 
  ylab("First line \nSecond Line") + 
  theme(axis.title.y = element_text(angle = 0, vjust = 1))

image

iamstein commented 1 year ago

To make sure users don't have a horizontal ylabel that is too long, we could do some string checking and manipulation, so if the ylabel is really long, we could figure out a reasonable way to insert “\n” characters. And there could be a default “maximum character length” option of say 20, that the user can tweak, or just make their own custom string with “\n”s where they want. I bet there’s even some R function or other for splitting strings in a smart way we may or may not want to use.

iamstein commented 1 year ago

This really only would reduce code from 2 lines to 1 line, it's not a big advantage, so we won't make this high priority