[R] ggplot2 stat_smooth formula different units
David Winsemius
dw|n@em|u@ @end|ng |rom comc@@t@net
Thu Nov 12 03:14:15 CET 2020
On 11/11/20 2:11 PM, Marcelo Laia wrote:
> Hi,
>
> I am running these approaches:
>
> Model 1
>
> ggplot( dat , aes(x=DAP, y=Altura, color=as.factor(Espacamento) )) +
> geom_point(size=0.5) +
> stat_smooth(method = "lm",
> formula = y ~ x + I(x^2), size = 1) +
> facet_grid(Espacamento ~ Clone) +
> theme(legend.position="none")
>
> Model 2
>
> ggplot( dat , aes(x=DAP, y=Altura, color=as.factor(Espacamento) )) +
> geom_point(size=0.5) +
> stat_smooth(method = "lm",
> formula = I(log(y)) ~ I(1/x), size = 1) +
> facet_grid(Espacamento ~ Clone) +
> theme(legend.position="none")
Removing the I(.) calls has no effect.
I think you should reshape that formula to the equivalent form with no
transformation on the LHS:
ggplot( dat , aes(x=DAP, y=Altura, color=as.factor(Espacamento) )) +
geom_point(size=0.5) +
stat_smooth(method = "lm",
formula = y ~ exp(1/x), size = 1) +
facet_grid(Espacamento ~ Clone) +
theme(legend.position="none")
--
David.
>
> In model 1, both, original variables and fitted variables are plotted
> in the same units.
>
> However, in the second one, points is plotted in the original variable,
> instead of fitted variables. I know that
>
> exp(fitted(model2))
>
> do the trick and return the variables to the original units.
>
> But, I don't know how I do this in the stat_smooth function.
>
> Please, have you a tip for help me?
>
> Thank you!
>
More information about the R-help
mailing list