最簡單的解決方案:使用Unicode字符
不需要expression
或其他包裹。
不確定這是否是ggplot的新功能,但它確實(shí)有效。它還可以輕松混合希臘語和常規(guī)文本(例如在刻度線中添加'*')
只需在文本字符串中使用unicode字符即可。似乎適用于我能想到的所有選項(xiàng)。 編輯:它在facet標(biāo)簽中不起作用。為了保持一致性,仍然試圖用unicode解決這個(gè)問題。
library(ggplot2)ggplot(mtcars,
aes(mpg, disp, color=factor(gear))) +
geom_point() +
labs(title="Title (\u03b1 \u03a9)", # works fine
x= "\u03b1 \u03a9 x-axis title", # works fine
y= "\u03b1 \u03a9 y-axis title", # works fine
color="\u03b1 \u03a9 Groups:") + # works fine
scale_x_continuous(breaks = seq(10, 35, 5),
labels = paste0(seq(10, 35, 5), "\u03a9*")) + # works fine; to label the ticks
ggrepel::geom_text_repel(aes(label = paste(rownames(mtcars), "\u03a9*"))) # works fine for text labels in plot
由reprex包創(chuàng)建于2018-11-14 (v0.2.1)