You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to create facet labels dynamically. The labels come from a data frame and contain Greek letters. label_bquote alone fails to replace the Greek letter name stored in a variable with the symbol. Incorporating rlang::sym() around the variable names used to fix the issue, but now throws an error. However, this strategy still works when using bquote. The first piece of code below is from a solution to the stackoverflow post How can I make bquote replace the greek letter stored in a variable with the symbol?
### this works
library("tidyverse")
a<-"alpha"b<-"beta"
ggplot(data.frame(x= c(1), y= c(1)), aes(x, y)) +
geom_point() +
labs(x= bquote(.(sym(a))[.(sym(b))])) +
labs(y= bquote(alpha[beta]))
### this used to work, but now throws an error
library("tidyverse")
df<-data.frame(x= rep(1:5, 2),
y= rnorm(10),
facet_var= rep(c("alpha", "beta"), times= c(5, 5)))
df#> x y facet_var#> 1 1 -1.14089312 alpha#> 2 2 0.08233709 alpha#> 3 3 -1.17177333 alpha#> 4 4 1.00633917 alpha#> 5 5 -0.01021232 alpha#> 6 1 -1.48566764 beta#> 7 2 0.32726416 beta#> 8 3 -0.72468232 beta#> 9 4 0.88635594 beta#> 10 5 2.04821051 beta
ggplot(df, aes(x, y)) +
geom_point() +
facet_grid(facet_var~.,
labeller= label_bquote(rows= .(sym(facet_var))))
#> Error in sym(facet_var): could not find function "sym"### trying to be more explicit about sym doesn't seem to help
ggplot(df, aes(x, y)) +
geom_point() +
facet_grid(facet_var~.,
labeller= label_bquote(rows= .(rlang::sym(facet_var))))
#> Error in rlang::sym: could not find function "::"
Thanks, confirmed. The problem is here; since params is supplied, bquote() only searches in params not in the other environments. Probably we should create an environment contains params instead of a list so that bquote() can search in the parent environments.
I want to create facet labels dynamically. The labels come from a data frame and contain Greek letters. label_bquote alone fails to replace the Greek letter name stored in a variable with the symbol. Incorporating rlang::sym() around the variable names used to fix the issue, but now throws an error. However, this strategy still works when using bquote. The first piece of code below is from a solution to the stackoverflow post How can I make
bquote
replace the greek letter stored in a variable with the symbol?Created on 2020-07-20 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: