将表达式对象组合到单个文本字符串中,用于ggplot标签
我正在尝试在GGPLOT中创建标签,该标签由字符矢量和表达式组成,并将其组合成单个标签。我希望这些字符和表达式来自对象,以便我可以轻松地使用函数将它们交换为使用GGPLOT创建的不同图。
不幸的是,我缺乏结合存储在对象中的表达式所需的语法知识。我的情况如下所述:
library(ggplot2)
data(iris)
sup <- bquote(super^1)
sub <- bquote(sub[1])
ggplot() +
geom_point(data = iris, aes(x = Sepal.Length, y = Sepal.Width)) +
labs(x = expression('Static text: '~sup~sub))
我尝试了bquote(),quote(),替代()和我尝试表达式(粘贴('主文本',sup,sub)的组合。我还尝试了eval()函数以查看 它将迫使对象作为表达式中的表达式读取。
如果由于我对语法的了解有限, 堆栈溢出是我要学习这些东西的地方
因此,
。 sstatic.net/qpi3g.png“ rel =“ nofollow noreferrer”>
I am trying to create labels in ggplot that are comprised of character vectors and expressions combined into a single label. I want the characters and expressions to be sourced from objects so that I can easily use a function to swap them for different plots created using ggplot.
Unfortunately I lack the syntax knowledge needed to combine expressions stored in objects. My situation is described below:
library(ggplot2)
data(iris)
sup <- bquote(super^1)
sub <- bquote(sub[1])
ggplot() +
geom_point(data = iris, aes(x = Sepal.Length, y = Sepal.Width)) +
labs(x = expression('Static text: '~sup~sub))
I have tried combinations of bquote(), quote(), substitute(), and I tried expression(paste('Main text', sup, sub). I also tried the eval() function to see if it would force the objects to be read as expressions inside the expression.
Because of my limited knowledge of syntax, I don't know what other options are available. It has been difficult to find advanced R resources that explain syntax for such specific situations so stack overflow has been the place I go to learn these things.
My main goal is to make it look like this, but importing text from an object instead of writing directly into the expression:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以将其包装在
bquote
-output
We can wrap it within
bquote
-output