gpt4 book ai didi

r - geom_smooth 没有出现在 ggplot 上

转载 作者:行者123 更新时间:2023-12-01 00:06:20 24 4
gpt4 key购买 nike

我正在做一些粘度实验,我正在尝试用 ν 与 θ 绘制 Eyring 图。
当我使用 ggplot2 创建绘图时我无法显示我的模型。

这些是使用的值:

> theta
[1] 25 30 35 40 45
> nu
[1] 1.448462 1.362730 1.255161 1.167408 1.083005

在这里,我使用上面的值创建了图:
plot <-
ggplot()+
geom_point(mapping = aes(theta, nu), colour = "#0072bd", size = 4, shape = 16)+
theme_bw()+
labs(
x = expression(paste(theta, " ", "[°C]")),
y = expression(paste("ln(", nu, ")", " ", "[mPa*s]")))+
ylim(0, 10)+
xlim(0, 100)

That's what the plot looks like.

现在,我用 geom_smooth() 添加我的模型
plot +
geom_smooth(
method = "nls",
method.args = list(formula = nu~a*exp(b/theta),
start=list(a=1, b=0.1)))

但什么也没发生……甚至没有错误信息,情节看起来和以前一样。

我也试过把 formula直接作为 geom_smooth()参数和起始值也是如此,
plot +
geom_smooth(
method = "nls",
formula = nu~a*exp(b/theta),
start=list(a=1, b=0.1))

但后来我得到了

Error:Unknown parameter: start



任何人都可以找到我犯的错误吗?

提前致谢!

干杯

编辑

在分离美学映射时,
plot <-
ggplot()+
aes(theta, nu)+
geom_point(colour = "#0072bd", size = 4, shape = 16)+
theme_bw()+
labs(
x = expression(paste(theta, " ", "[°C]")),
y = expression(paste("ln(", nu, ")", " ", "[mPa*s]")))+
ylim(0, 10)+
xlim(0, 100)

我收到以下错误(仍然没有任何变化):

警告信息:

1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to min; returning -Inf 3: Computation failed in stat_smooth(): $ operator is invalid for atomic vectors

最佳答案

您有几件事情正在发生,其中许多已在评论中指出。

一旦您将变量放入 ggplot 的 data.frame 中并在 ggplot 中全局定义您的美学或在每个 geom 内,主要发生在 geom_smooth 中的公式期待您引用yx而不是变量名。 geom_smooth将使用您映射到的变量 yxaes .

您将遇到的另一个复杂情况概述 here .因为你没有从 predict.nls 得到标准错误,您需要使用 se = FALSEgeom_smooth .

这是您的 geom_smooth代码可能如下所示:

geom_smooth(method = "nls", se = FALSE, 
method.args = list(formula = y~a*exp(b/x), start=list(a=1, b=0.1)))

这是完整的代码和情节。
ggplot(df, aes(theta, nu))+
geom_point(colour = "#0072bd", size = 4, shape = 16)+
geom_smooth(method = "nls", se = FALSE,
method.args = list(formula = y~a*exp(b/x), start=list(a=1, b=0.1))) +
theme_bw()+
labs(
x = expression(paste(theta, " ", "[°C]")),
y = expression(paste("ln(", nu, ")", " ", "[mPa*s]")))+
ylim(0, 10) +
xlim(0, 100)

enter image description here
请注意 geom_smooth除非您使用 fullrange = TRUE,否则不会超出数据集的范围而不是默认值。如果您只有 5 个数据点,这可能非常值得怀疑。
ggplot(df, aes(theta, nu))+
geom_point(colour = "#0072bd", size = 4, shape = 16)+
geom_smooth(method = "nls", se = FALSE, fullrange = TRUE,
method.args = list(formula = y~a*exp(b/x), start=list(a=1, b=0.1))) +
theme_bw()+
labs(
x = expression(paste(theta, " ", "[°C]")),
y = expression(paste("ln(", nu, ")", " ", "[mPa*s]")))+
ylim(0, 10) +
xlim(0, 100)

enter image description here

关于r - geom_smooth 没有出现在 ggplot 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36609178/

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