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") 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! -- Marcelo
Hello, Try removing I() from I(log(y)). But it's hard to say without a reproducible example, please post the output of dput(dat) or, if dat is big, the output of dput(head(dat, 20)) Hope this helps, Rui Barradas ?s 22:11 de 11/11/20, Marcelo Laia escreveu:> 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") > > 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! >
Hi Rui, You are very welcome! On 11/11/20 at 11:10, Rui Barradas wrote:> > dput(head(dat, 20)) >structure(list(Bloco = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), Espacamento = c("3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1", "3 x 1"), Clone = c("AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020", "AEC 0020"), Sulco = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L), Arvore = c(1L, 3L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 1L, 2L, 4L, 5L, 6L, 8L, 9L, 10L, 11L, 1L, 2L), DAP = c(7, 7.73, 7.64, 9.61, 11.94, 11.46, 11.68, 11.84, 13.37, 11.14, 10.5, 12.19, 7.23, 8.94, 9.99, 12.67, 5.09, 6.37, 10.28, 8.12), Altura = c(14.8, 17.2, 14.8, 17.2, 18.5, 19.2, 19.2, 18, 19.3, 18.2, 18.1, 18.1, 15.7, 17.1, 19.3, 19.2, 10.9, 13.2, 17.1, 16.5), Observacao = c("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "")), row.names = c(1L, 3L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 18L, 19L, 20L, 21L, 22L, 23L), class = "data.frame") -- Marcelo
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! >