How come I can’t return an element_text()
> ifelse(TRUE,element_text(size=20),element_text(size=10))
[[1]]
NULL
but I can do this?
> element_text(size=20)
List of 8
$ family : NULL
$ face : NULL
$ colour : NULL
$ size : num 20
$ hjust : NULL
$ vjust : NULL
$ angle : NULL
$ lineheight: NULL
- attr(*, "class")= chr [1:2] "element" "element_text"
You can just not in the way you’re trying to use it:
Here’s an example of what I mean:
It has to do with the
ifelseyou’re using (ifelse) that’s vectorized. I think you’re afterif(){}else{}as in:though I really wouldn’t format it this way but kept it to one line to allow comparison to your method.
The problem isn’t
ggplot2but your use ofifelse. Check out?ifelseand the documentation says:In your question you show the output of
element_text(size=10)that does not resembletestin structure.