我正在进行一些粘度实验,我正试图用ν对θ进行Eyring绘图.当我创建情节时,ggplot2我无法显示我的模型.
这些是使用的值:
> theta
[1] 25 30 35 40 45
> nu
[1] 1.448462 1.362730 1.255161 1.167408 1.083005
Run Code Online (Sandbox Code Playgroud)
在这里,我使用上面的值创建绘图:
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)
Run Code Online (Sandbox Code Playgroud)
现在,我添加我的模型 geom_smooth()
plot +
geom_smooth(
method = "nls",
method.args = list(formula = nu~a*exp(b/theta),
start=list(a=1, b=0.1)))
Run Code Online (Sandbox Code Playgroud)
但没有任何反应......甚至没有错误信息,情节看起来和以前一样.
我也尝试将formula直接作为geom_smooth()参数和起始值,
plot +
geom_smooth(
method = "nls",
formula = nu~a*exp(b/theta),
start=list(a=1, b=0.1))
Run Code Online (Sandbox Code Playgroud)
但后来我得到了
错误:未知参数:启动
谁能找到我犯的错误?
提前致谢!
干杯
编辑
在分离美学映射时,
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)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误(仍然没有任何变化):
警告信息:
1:在min(x)中:min没有非缺失参数; 返回Inf 2:在max(x)中:min没有非缺失参数; 返回--Inf 3:stat_smooth()中的计算失败:$运算符对原子向量无效
你有几件事情正在发生,其中许多都在评论中指出.
一旦你将变量放在data.frame中,ggplot并在全局ggplot或每个内部定义你的美学geom,那么主要的是公式中geom_smooth需要你引用y而x不是变量名. geom_smooth将使用您映射到变量y和x在aes.
您将遇到另一个复杂问题.因为你没有得到从标准错误predict.nls,你需要使用se = FALSE在geom_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)))
Run Code Online (Sandbox Code Playgroud)
这是完整的代码和情节.
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)
Run Code Online (Sandbox Code Playgroud)
请注意,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)
Run Code Online (Sandbox Code Playgroud)