# [R] help with ggplot2

Ronaldo Reis Júnior chrysopix at gmail.com
Fri Jan 29 15:11:07 CET 2016

Hi,

I found a solution.

expfun <- function(x,intercept=intercept,slope=slope)
{exp(intercept+slope*x)}

mean\$treat <- as.factor(paste(mean\$A,mean\$B,sep=""))

ggplot(mean, aes(x=x, y=y)) +
geom_errorbar(aes(ymin=y-SE, ymax=y+SE), width=.1)+
geom_point()+
stat_function(fun =
expfun,args=list(intercept=4.319735,slope=-0.098362),data=subset(mean,mean\$treat=="A1B1"))+
stat_function(fun =
expfun,args=list(intercept=4.350256,slope=-0.098362),data=subset(mean,mean\$treat=="A1B2"))+
stat_function(fun =
expfun,args=list(intercept=4.920225,slope=-0.238536),data=subset(mean,mean\$treat=="A2B1"))+
stat_function(fun =
expfun,args=list(intercept=5.257911,slope=-0.238536),data=subset(mean,mean\$treat=="A2B2"))+
facet_grid(A~B)

Its work, maybe not elegant, but work.

Inte
Ronaldo

Em 29-01-2016 09:10, Ronaldo Reis Júnior escreveu:
> Hi,
>
> I try to put 4 different curves to 4 different grids using ggplot2
> package. But, I dont know how.
>
> I have something like this:
>
> A1B1 <- function(x) {exp(4.319735-0.098362*x)}
> A1B2 <- function(x) {exp(4.350256-0.098362*x)}
> A2B1 <- function(x) {exp(4.920225-0.238536*x)}
> A2B2 <- function(x) {exp(5.257911-0.238536*x)}
> ggplot(mean, aes(x=xvalue, y=yvalue)) +
>   geom_errorbar(aes(ymin=yvalue-SE, ymax=yvalue+SE), width=.1)+
>   geom_point()+
>   facet_grid(A~B)
>
> Ok, the mean+-SE graphs work. But how I can made to put each equation
> on correct grid? I try to use the stat_function(fun = A1B1), but it
> put the equation on all grids, not only on A1B1 grid.
>
> Any idea?
>
> Thanks
> Ronaldo
>
>
> --
> 1
>
> > Prof. Ronaldo Reis Júnior
> |  .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional
> | : :'  : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia
> | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil
> |   `- Fone: (38) 3229-8192 |ronaldo.reis em unimontes.br
> |http://www.ppgcb.unimontes.br/lecc  | LinuxUser#: 205366

--
1

> Prof. Ronaldo Reis Júnior
|  .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional
| : :'  : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia
| `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil
|   `- Fone: (38) 3229-8192 | ronaldo.reis em unimontes.br
| http://www.ppgcb.unimontes.br/lecc | LinuxUser#: 205366

[[alternative HTML version deleted]]