so I am struggling to get a plot working like I want. I have a facet_grid where the variables facetted is determined dynamically in a shiny app...
facet_grid(facetFormula, labeller = label_both)
where...
facetFormula <- as.formula(paste(input$filter2Var, "~", input$filter1Var))
this works fine, except that i'd rather a linebreak as the variable "name: value" separator instead of the colon. i've poked around with other arguments (multi_line
, sep
), using label_both()
or label_wrap_gen()
or labeller()
instead of label_both
no parenthesis... and am getting no where, probably stumbling over the already complex issue of dynamic variables to be facetted by. i've tried treating arguments to these various functions with !!sym()
or as.formula()
, but i really don't know what i am doing and probably messing up several things in trying to just add some simple text wrapping to my facet labels. any help is much appreciated!
UPDATE...
cases <- c("case1_has_long_name", "case2_long_too", "case3_long_as_well", "case4_also_long", "case5_long")
the_first_variable <- cases[round(runif(100,1,3))]
variable_number_two <- cases[round(runif(100,1,5))]
var1 <- "the_first_variable"
var2 <- "variable_number_two"
facetFormula <- as.formula(paste(var1, "~", var2))
myX <- runif(100,0,10)
myY <- runif(100,-5,5)
myData <- data.frame(myX, myY, the_first_variable, variable_number_two)
ggplot(myData, aes(x = myX, y = myY)) +
geom_point(alpha = .5) +
facet_grid(facetFormula,
labeller = label_both)
this generates a plot with my issue, where the facet labels are too big. i just want to learn how to make the labels wrap. was thinking as a simple start, instead of ":" as the separator between variable name and variable value, i could use "\n" as the seperator. the awkwardness of specifying my facet variables as variable themselves comes from them being dynamically defined in a shiny app.