43

このように生成されたプロットがあります:

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")

私は次のようにx軸ラベルを制御します:

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

これは機能しますが、">80"ラベルを"≥80"に変更する必要があります。

ただし、「≥80」は「=80」と表示されます。

大なり記号を表示するにはどうすればよいですか?

4

4 に答える 4

54

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.

于 2012-11-02T13:53:15.643 に答える
21

式を渡すことができます(引数内のphantom(...)先頭を偽造することを含む>=labelscale_x_discrete(...)

例えば

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

ここに画像の説明を入力してください

?plotmath数式の作成と この 関連するSOの質問と回答の詳細については、を参照してください。

于 2012-11-02T11:19:23.077 に答える
10
plot(5, ylab=expression("T ">="5"))

ここに画像の説明を入力してください

于 2015-11-30T09:18:49.100 に答える
2

使用できます

expression("">=80)

したがって、次のような全軸ラベルは次のようになります。

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

Unicodeを使用しているときにプロットをエクスポートするのに問題がありましたが、式関数の方が一貫性があります。

于 2019-10-21T14:43:44.583 に答える