gpt4 book ai didi

r - geom_smooth 与 R 中的字符串

转载 作者:行者123 更新时间:2023-12-04 09:40:15 27 4
gpt4 key购买 nike

我有一个变量我想用于 ggplots 中的 y 轴,它必须作为它的“”名称传递(出于类似的原因,我可以在那里使用一些变量并希望改变 y 轴标签来反射(reflect)它)。

但我也想在图表上绘制一条平滑的线。

ggplot(data=iris, aes(x=Sepal.Width, col=Species)) +
geom_point(aes_string(y="Petal.Length")) +
geom_smooth(method="lm", formula=y~x, se=F)

Error: stat_smooth requires the following missing aesthetics: y .有什么办法吗?

最佳答案

您在找 help('get') ?它会

Return the Value of a Named Object



并将其用作 y坐标绘制数据。
library(ggplot2)

ggplot(data=iris, aes(x=Sepal.Width, y = get("Petal.Length"), color=Species)) +
geom_point() +
geom_smooth(method="lm", formula=y~x, se=F)

enter image description here

关于r - geom_smooth 与 R 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62364353/

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