Displaying a greater than or equal sign

前端 未结 4 1486
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 06:11

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=         


        
相关标签:
4条回答
  • 2020-11-30 06:53

    You can use

    expression("">=80)
    

    So your full axis label like would look like:

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

    I have had trouble exporting plots when using unicode, but the expression function is more consistent.

    0 讨论(0)
  • 2020-11-30 06:54
    plot(5, ylab=expression("T ">="5"))
    

    0 讨论(0)
  • 2020-11-30 07:01

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

    .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.

    0 讨论(0)
  • 2020-11-30 07:04

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

    for example

     .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], expression(phantom(x) >=80))
    

    enter image description here

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

    0 讨论(0)
提交回复
热议问题