gpt4 book ai didi

r - geom_text 中的数学符号错误

转载 作者:行者123 更新时间:2023-12-01 08:49:56 26 4
gpt4 key购买 nike

在文本中插入数学符号不应该像我想象的那么复杂!

OTH,甚至看起来相似的例子
ggplot2 facet_wrap with mathematical expression

我仍然无法将Ω(欧米茄)符号插入geom_text !

假设您有基本的散点图,并且您想为每个方面添加带有 (Omega) 数学符号的平均值,

mean.Petal <- aggregate(iris["Petal.Width"], iris["Species"], mean)
Species Petal.Width
1 setosa 0.246
2 versicolor 1.326
3 virginica 2.026

ggplot(iris) +
geom_point(aes(y=Sepal.Length,x=Sepal.Width ,col=factor(Species))) +
facet_wrap(~ Species)+
geom_text(data = mean.Petal, parse = TRUE,
aes(x = 4.5, y = 7, label=sprintf('mean_Petal=%.2f %s',
round(Petal.Width,digits=2),'Omega')))

Error in parse(text = as.character(lab)) : :1:17: unexpected symbol 1: mean_Petal=0.25 Omega



再试一次
geom_text(data = mean.Petal, parse = TRUE,
aes(x = 4.5, y = 7, label=paste('mean_Petal=',
round(Petal.Width,digits=2),expression(Omega),sep=' ')))

Error in parse(text = as.character(lab)) : :1:18: unexpected symbol 1: mean_Petal= 0.25 Omega

最佳答案

使用时geom_textparse = TRUE ,你想把一个对应于 plotmath 的字符串放在一起表达式,所以你可以这样做:

ggplot(iris) +
geom_point(aes(y=Sepal.Length,x=Sepal.Width ,col=factor(Species))) +
facet_wrap(~ Species)+
geom_text(data = mean.Petal, parse = TRUE,
aes(x = 3, y = 7,
label=paste("'Mean petal' ==", round(Petal.Width, digits=2), "* Omega")))

关于r - geom_text 中的数学符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44875933/

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