Jaume Tormo
2020-Oct-20 16:24 UTC
[R-es] Dibujar un gráfico con 4 terms - ggeffects + plot
Hola eRRer en s,
He creado un modelo mixto (adjunto) con lme4
He dibujado la predicción usando:
df <- ggpredict(m.glob.pre.anu
, terms = c("pre", "area_m2",
"sum.vs.win")
)
plot(df)
Luego he arreglado el gráfico usando:
df <- ggpredict(m.glob.pre.anu
, terms = c("pre", "area_m2",
"sum.vs.win")
)
plot(df)+
labs(title = "Predicted number of annuals" # falla al posar 4 terms
en el
df
,x = "MAP"
,y = "Proportion of annuals"
) +
scale_x_continuous(breaks = c(-2,0,2)
, labels= etiquetas
) +
labs(color="Area")
Pero me interesa más el modelo con 4 terms que sería:
df <- ggpredict(m.glob.pre.anu
, terms = c("pre", "area_m2",
"sum.vs.win", "data_type")
)
plot(df)
Hasta aquí funciona todo.
Pero si intento hacer los arreglos p.e.:
plot(df)+
labs(title = "Predicted number of annuals"
,x = "MAP"
,y = "Proportion of annuals"
)
Me da el siguiente error:
Error in plot(df) + labs(title = "Predicted number of annuals", x =
"MAP",
:
non-numeric argument to binary operator
Creo que el error se debe a que en el modelo ahora hay 4 terms en lugar de
3 ¿Puede ser?
¿Se os ocurre qué puede estar pasando? ¿Sabéis cómo puedo especificar los
títulos, leyendas, etc. de otra forma?
Muchas gracias de antemano.
--
Dr. Jaume Tormo.
Area of Ecology
Department of Agrarian and Environmental Sciences
Technological College. Agri-food and Environment
University of Zaragoza, Spain
0034 974292678
https://es.linkedin.com/in/jaumetormo
https://acercad.wordpress.com/
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL:
<https://stat.ethz.ch/pipermail/r-help-es/attachments/20201020/d3862921/attachment-0001.html>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: modelo.RData
Type: application/octet-stream
Size: 130468 bytes
Desc: no disponible
URL:
<https://stat.ethz.ch/pipermail/r-help-es/attachments/20201020/d3862921/attachment-0001.obj>
Jaume Tormo
2020-Oct-21 11:34 UTC
[R-es] Dibujar un gráfico con 4 terms - ggeffects + plot
Hola de nuevo,
Me he dado cuenta de que cuando haces el modelo con 3 terms crea un objeto
diferente que cuando lo haces con 4 terms p.e.
# gráfica MAP vs prop.anu 3 terms
df <- ggpredict(m.glob.pre.anu
, terms =
c("pre","area_m2","sum.vs.win")
)
p.tot<-plot(df) # al hacer esto, guarda plot(df) en p.tot y no dibuja nada
# gráfica MAP vs prop.anu 4 terms
df <- ggpredict(m.glob.pre.anu
, terms = c("pre", "area_m2",
"sum.vs.win", "data_type")
)
p<-plot(df) # al hacer esto, guarda plot(df) en p pero dibuja en gráfico
str(p); attributes(p)
str(p.tot); attributes(p.tot)
Crea dos objetos diferentes... p.tot tiene que ver con gtable()
Editar eso resulta bastante complicado:
https://stackoverflow.com/questions/46516269/retrieve-facet-labels-from-a-ggplot-or-a-gtable-gtree-grob-gdesc-object
Creo que voy a crear los dos gráficos por separado y juntar las dos
imágenes en una. O bien probar con layout() o grid()
¿Alguna sugerencia?
Jaume.
El mar., 20 oct. 2020 a las 18:24, Jaume Tormo (<jautorbla en gmail.com>)
escribió:
> Hola eRRer en s,
>
> He creado un modelo mixto (adjunto) con lme4
> He dibujado la predicción usando:
> df <- ggpredict(m.glob.pre.anu
> , terms = c("pre", "area_m2",
"sum.vs.win")
> )
> plot(df)
> Luego he arreglado el gráfico usando:
> df <- ggpredict(m.glob.pre.anu
> , terms = c("pre", "area_m2",
"sum.vs.win")
> )
> plot(df)+
> labs(title = "Predicted number of annuals" # falla al posar 4
terms en el
> df
> ,x = "MAP"
> ,y = "Proportion of annuals"
> ) +
> scale_x_continuous(breaks = c(-2,0,2)
> , labels= etiquetas
> ) +
> labs(color="Area")
> Pero me interesa más el modelo con 4 terms que sería:
> df <- ggpredict(m.glob.pre.anu
> , terms = c("pre", "area_m2",
"sum.vs.win",
> "data_type")
> )
> plot(df)
> Hasta aquí funciona todo.
> Pero si intento hacer los arreglos p.e.:
> plot(df)+
> labs(title = "Predicted number of annuals"
> ,x = "MAP"
> ,y = "Proportion of annuals"
> )
> Me da el siguiente error:
> Error in plot(df) + labs(title = "Predicted number of annuals", x
= "MAP",
> :
> non-numeric argument to binary operator
> Creo que el error se debe a que en el modelo ahora hay 4 terms en lugar de
> 3 ¿Puede ser?
> ¿Se os ocurre qué puede estar pasando? ¿Sabéis cómo puedo especificar los
> títulos, leyendas, etc. de otra forma?
>
> Muchas gracias de antemano.
>
> --
> Dr. Jaume Tormo.
> Area of Ecology
> Department of Agrarian and Environmental Sciences
> Technological College. Agri-food and Environment
> University of Zaragoza, Spain
> 0034 974292678
> https://es.linkedin.com/in/jaumetormo
> https://acercad.wordpress.com/
>
>
--
Jaume Tormo.
https://es.linkedin.com/in/jaumetormo
https://acercad.wordpress.com/
[[alternative HTML version deleted]]