我正在尝试构建一个包含Unicode字符(正负sign U + 00B1)的绘图
以下是一些虚假数据:
htop
这是到目前为止我的情节代码:
library(tidyverse)
set.seed(1)
df <- crossing(
Rated_Movement = c("Running", "Jumping"),
Rater = c("John Snow", "Batman", "Hulk")) %>%
mutate(
Error = runif(n = 6, min = 0, max=2))
有没有办法将+-更改为Unicode字符U + 00B1
我尝试使用反斜杠进行转义: paste(“ \ U + 00B1”,round(Error,2)) 但是我得到了错误: “错误:'\ U'在字符串中以““ \ U”开头但不以十六进制数字表示”
任何帮助将不胜感激。 最好的问候
答案 0 :(得分:2)
有两种方法:
ggplot(df, aes(x = Rated_Movement, y = Rater, fill = Error)) +
geom_tile(color = "black", size = 0.5, alpha = 0.8)+
geom_text(aes(label = paste("±", round(Error,2))))+
scale_fill_gradientn(colours = terrain.colors(10))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
ggplot(df, aes(x = Rated_Movement, y = Rater, fill = Error)) +
geom_tile(color = "black", size = 0.5, alpha = 0.8)+
geom_text(aes(label = paste("\u00B1", round(Error,2)))) +
scale_fill_gradientn(colours = terrain.colors(10))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())