Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify ggplot2 labeller options without passing label values

Tags:

r

ggplot2

facet

I have a facetted point plot, and the facets are based on multiple factors:

p = p + facet_wrap(~ model + run, ncol = 1, scales = 'fixed')

I'm happy with ggplot2 using the existing unique values of model and run to build the facet labels, but I'd like to have them across one line, not multiple. However,

p = p + facet_wrap(~ model + run, ncol = 1, scales = 'fixed',
  labeller = label_value(multi_line = FALSE)

results in a missing argument error, because label_value() expects the argument labels first:

Error in lapply(labels, as.character) :
  argument "labels" is missing, with no default

I'm not sure how to supply this given there are multiple facetting variables specified. If I leave the labeller out entirely, ggplot2 seems happy to work it out itself.

like image 925
jimjamslam Avatar asked Mar 18 '26 20:03

jimjamslam


1 Answers

You want to pass the function without calling it (it will be called with the labels when constructing the plot), so:

p = p + facet_wrap(~ model + run, ncol = 1, scales = 'fixed',
  labeller = function(labs) {label_value(labs, multi_line = FALSE)})
like image 70
Marius Avatar answered Mar 21 '26 11:03

Marius