我想將以下文字放在 ggplot 圖表后面

我認為它應該很容易實作。不幸的是,我所有的嘗試都以完全失敗告終。我已經在這個論壇上閱讀了十幾篇關于這個主題的帖子。我已經做了幾十次嘗試,但仍然沒有達到我期望的效果。順便說一下,我注意到對 unicode 符號的一種相當奇怪的處理。請比較下表中的標題和副標題。
library(tidyverse)
ggplot()
labs(
title = expression("\u00AE \u00A9, \u00A2, \u00BC, \u00BD, \u00BE, \u00A5, \u00D8, \u00F8"),
subtitle = "\u00AE \u00A9, \u00A2, \u00BC, \u00BD, \u00BE, \u00A5, \u00D8, \u00F8"
)
annotate(geom="text", label="\u00D828.15^{ 0.15}", x=0, y=0.08,parse = TRUE, size=5)
annotate(geom="text", label="\u00D8", x=0, y=0, size=5)
annotate(geom="text", label="28.15^{ 0.15}", x=0.03, y=0.001,parse = TRUE, size=5)
xlim(c(-0.1, 0.1))
ylim(c(-0.02, 0.1))
theme_void()

為什么某些 unicode 符號在放置在expression函式中或使用該parse選項時會丟失一些圖形?這發生在符號 ¢、¥、?、?、?、? 上。就我而言,我特別關心符號 ?。我終于得到了對軌跡圖的影響(圖表底部的注釋)是從兩個彼此相鄰的注釋的繁瑣設定中創建的。但是,一旦我更改圖表的大小,它就會完全崩潰。
有誰知道如何解決這個問題?
非常感謝您的快速回復。不幸的是,它仍然對我不起作用!:-(
library(latex2exp)
library(ggplot2)
label <- TeX("$?28.15^{ 0.15}$")
qplot(1, "A")
annotate(geom = "text", label = label, x = 1, y = 1.1, size = 10)
xlab(label)

uj5u.com熱心網友回復:
您可以在 math ( $) 環境中使用 LaTeX 語法來自動生成 plotmath 運算式:
library(latex2exp)
library(ggplot2)
label <- TeX("$?28.15^{ 0.15}$")
label
#> expression(`$?28.15^{ 0.15}$` = paste("", "?28", ".", "15",
#> phantom()^{
#> paste(" 0", ".", "15")
#> }, ""))
qplot(1, "A")
annotate(geom = "text", label = label, x = 1, y = 1.1, size = 10)
xlab(label)
#> Warning in is.na(x): is.na() applied to non-(list or vector) of type
#> 'expression'

由reprex 包(v2.0.1)于 2021 年 10 月 18 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/325058.html
