I'm trying to add aa custom facet label to a plot that was facetted with facet_grid()
as follows:
p <- qplot(wt, mpg, data = mtcars)
p <- p + facet_grid(. ~ vs, labeller = label_bquote(alpha^a==alpha^b))
This still works fine. However, when I add the variable on which I'm splitting to the equation in the facet label, like this:
p <- qplot(wt, mpg, data = mtcars)
p <- p + facet_grid(. ~ vs, labeller = label_bquote(alpha^a==alpha^b==.(x)))
I'm getting the following error:
Error: unexpected '==' in " p <- p + facet_grid(. ~ vs, labeller = label_bquote(alpha^a==alpha^b=="
Could someone help me out on this seemingly trivial problem?
It's not that you're adding the variable, it's the second ==
that causes the problem. This is an issue with the way R parses the operators. You can control what R sees with {}
:
p <- p + facet_grid(. ~ vs, labeller = label_bquote({alpha^a==alpha^b}==.(x)))
如果您只是添加适当的括号,这将有效。
p <- p + facet_grid(. ~ vs, labeller = label_bquote({alpha^a==alpha^b}==.(x)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.