如何在 ggplot 中为 "greater than or equal to " 登录添加订阅?
How to add subscription for the "greater than or equal to " sign in ggplot?
我正在尝试使用具有下标大于或等号的表达式作为我情节的 facet_grid 标题。表达式的乳胶版本如下
.
首先我用下面的代码在表达式中加上了大于等于号,可以被facet_grid
函数正确解析和显示。
data$type <- factor(data$type, levels = c('A holds', "A doesn't hold"),labels = c(expression(S>=T), expression(S<=T)))
.
但是当我尝试使用代码 expression(S>=[A]T)
添加订阅 A
时,R 一直向我报告错误
Unexpected token '['
.
关于如何将订阅合并为上面的胶乳有什么建议吗?
您需要在 [A]
之前有一个不可见的占位符才能获得合法的表达式 - 您可以为此使用 phantom
:
library(ggplot2)
data$type <- factor(data$type, levels = c('A holds', "A doesn't hold"),
labels = c(expression(S >=phantom(0)[A]~T),
expression(S <= phantom(0)[A]~T)))
ggplot(data, aes(x, y)) +
geom_point() +
facet_grid(.~type, labeller = label_parsed) +
theme(strip.text = element_text(size = 20))
由 reprex package (v2.0.1)
于 2022-04-06 创建
数据
data <- data.frame(x = rep(1:10, 2), y = rnorm(20),
type = rep(c('A holds', "A doesn't hold"), each = 10))
我正在尝试使用具有下标大于或等号的表达式作为我情节的 facet_grid 标题。表达式的乳胶版本如下
首先我用下面的代码在表达式中加上了大于等于号,可以被facet_grid
函数正确解析和显示。
data$type <- factor(data$type, levels = c('A holds', "A doesn't hold"),labels = c(expression(S>=T), expression(S<=T)))
.
但是当我尝试使用代码 expression(S>=[A]T)
添加订阅 A
时,R 一直向我报告错误
Unexpected token '[' .
关于如何将订阅合并为上面的胶乳有什么建议吗?
您需要在 [A]
之前有一个不可见的占位符才能获得合法的表达式 - 您可以为此使用 phantom
:
library(ggplot2)
data$type <- factor(data$type, levels = c('A holds', "A doesn't hold"),
labels = c(expression(S >=phantom(0)[A]~T),
expression(S <= phantom(0)[A]~T)))
ggplot(data, aes(x, y)) +
geom_point() +
facet_grid(.~type, labeller = label_parsed) +
theme(strip.text = element_text(size = 20))
由 reprex package (v2.0.1)
于 2022-04-06 创建数据
data <- data.frame(x = rep(1:10, 2), y = rnorm(20),
type = rep(c('A holds', "A doesn't hold"), each = 10))