显示大于或等于的符号

时间:2022-09-18 13:00:41

I have a plot which is generated thus:

我有一个这样产生的图:

ggplot(dt.2, aes(x=AgeGroup, y=Prevalence)) + 
    geom_errorbar(aes(ymin=lower, ymax=upper), colour="black", width=.2) +
    geom_point(size=2, colour="Red")

I control the x axis labels like this:

我像这样控制x轴标签:

scale_x_discrete(labels=c("0-29","30-49","50-64","65-79",">80","All")) +

This works but I need to change the ">80" label to "≥80".

这是可行的,但是我需要改变“> 80”标签“≥80”。

However "≥80" is displayed as "=80".

然而“≥80”显示为“= 80”。

How can I display the greater than or equal sign ?

如何显示大于或等于号?

3 个解决方案

#1


24  

An alternative to using expressions is Unicode characters, in this case Unicode Character 'GREATER-THAN OR EQUAL TO' (U+2265). Copying @mnel's example

使用表达式的另一种替代方法是使用Unicode字符,在这种情况下,Unicode字符“大于或等于”(U+2265)。复制@mnel的例子

.d <- data.frame(a = letters[1:6], y = 1:6)

ggplot(.d, aes(x=a,y=y)) + geom_point() + 
    scale_x_discrete(labels = c(letters[1:5], "\u2265 80"))

Unicode is a good alternative if you have trouble remembering the complicated expression syntax or if you need linebreaks, which expressions don't allow. As a downside, whether specific Unicode characters work at all depends on your graphics device and font of choice.

如果您难以记住复杂的表达式语法,或者需要换行符,而表达式不允许,那么Unicode就是一个不错的选择。不利的一面是,特定的Unicode字符是否有效完全取决于您的图形设备和选择的字体。

#2


19  

You can pass an expression (including phantom(...) to fake a leading >= within the label argument to scale_x_discrete(...)

您可以在scale_x_discrete(…)的标签参数中传递一个表达式(包括phantom(…)来伪造一个前导>=

for example

例如

 .d <- data.frame(a = letters[1:6], y = 1:6)

 ggplot(.x, aes(x=a,y=y)) + geom_point() + 
    scale_x_discrete(labels = c(letters[1:5], expression(phantom(x) >=80))

显示大于或等于的符号

See ?plotmath for more details on creating mathematical expressions and this related SO question and answer

参见plotmath,了解更多关于创建数学表达式和相关问题和答案的细节

#3


4  

plot(5, ylab=expression("T ">="5"))

显示大于或等于的符号

#1


24  

An alternative to using expressions is Unicode characters, in this case Unicode Character 'GREATER-THAN OR EQUAL TO' (U+2265). Copying @mnel's example

使用表达式的另一种替代方法是使用Unicode字符,在这种情况下,Unicode字符“大于或等于”(U+2265)。复制@mnel的例子

.d <- data.frame(a = letters[1:6], y = 1:6)

ggplot(.d, aes(x=a,y=y)) + geom_point() + 
    scale_x_discrete(labels = c(letters[1:5], "\u2265 80"))

Unicode is a good alternative if you have trouble remembering the complicated expression syntax or if you need linebreaks, which expressions don't allow. As a downside, whether specific Unicode characters work at all depends on your graphics device and font of choice.

如果您难以记住复杂的表达式语法,或者需要换行符,而表达式不允许,那么Unicode就是一个不错的选择。不利的一面是,特定的Unicode字符是否有效完全取决于您的图形设备和选择的字体。

#2


19  

You can pass an expression (including phantom(...) to fake a leading >= within the label argument to scale_x_discrete(...)

您可以在scale_x_discrete(…)的标签参数中传递一个表达式(包括phantom(…)来伪造一个前导>=

for example

例如

 .d <- data.frame(a = letters[1:6], y = 1:6)

 ggplot(.x, aes(x=a,y=y)) + geom_point() + 
    scale_x_discrete(labels = c(letters[1:5], expression(phantom(x) >=80))

显示大于或等于的符号

See ?plotmath for more details on creating mathematical expressions and this related SO question and answer

参见plotmath,了解更多关于创建数学表达式和相关问题和答案的细节

#3


4  

plot(5, ylab=expression("T ">="5"))

显示大于或等于的符号