gpt4 book ai didi

r - 在 ggplot2 中使用 Unicode 字符(加减号)

转载 作者:行者123 更新时间:2023-12-05 03:05:24 33 4
gpt4 key购买 nike

我正在尝试构建一个包含 unicode 字符的图(加减 sign U+00B1)

这是一些假数据:

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

到目前为止,这是我的情节代码:

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

剧情如下:
Plot

有没有办法可以将 +- 更改为 unicode 字符 U+00B1

我尝试使用反斜杠进行转义:粘贴(“\U+00B1”,圆(错误,2))但我得到错误:"错误:'\U' 在以“"\U""开头的字符串中未使用十六进制数字

任何帮助将不胜感激。最好的问候

最佳答案

有两种方式:

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

enter image description here

关于r - 在 ggplot2 中使用 Unicode 字符(加减号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51039262/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com