gpt4 book ai didi

r - ggplot 用希腊符号和 (1) 撇号或 (2) 在文本之间进行注释

转载 作者:行者123 更新时间:2023-12-04 11:37:41 24 4
gpt4 key购买 nike

无法在 ggplot 注释中添加希腊字母,当:它夹在其他文本之间,或相关文本包含撇号时。

例如,以下工作正常:

df <- data.frame(x =  rnorm(10), y = rnorm(10))
temp<-paste("rho == 0.34")
ggplot(df, aes(x = x, y = y)) + geom_point() +
annotate("text", x = mean(df$x), y = mean(df$y), parse=T,label = temp)

但是,当我这样做时,ggplot 会爆炸:
df <- data.frame(x =  rnorm(10), y = rnorm(10))
temp<-paste("Spearman's rho == 0.34")
ggplot(df, aes(x = x, y = y)) + geom_point() +
annotate("text", x = mean(df$x), y = mean(df$y), parse=T,label = temp)

ggplot 对这些特殊字符非常敏感。其他帖子似乎没有解决这个问题(如果没有,请道歉)。提前致谢。

最佳答案

我感受到了你的沮丧。诀窍,除了使用 expression对于@baptiste 评论的标签,传递您的标签 as.characterggplot .

df <- data.frame(x =  rnorm(10), y = rnorm(10))
temp <- expression("Spearman's"~rho == 0.34)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
annotate("text", x = mean(df$x), y = mean(df$y),
parse = T, label = as.character(temp))

enter image description here

关于r - ggplot 用希腊符号和 (1) 撇号或 (2) 在文本之间进行注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27303019/

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