[R-br] Como fazer para dois graficos do ggplot ficarem lado a lado
Pedro Emmanuel Alvarenga Americano do Brasil
emmanuel.brasil em gmail.com
Terça Maio 12 17:14:42 BRT 2015
Alison,
Obrigado... vou verificar essa solução. Ao mesmo tempo fuçando por ai
encontrei a seguinte funçao.
# Multiple plot function # # ggplot objects can be passed in ..., or to
plotlist (as a list of ggplot objects) # - cols: Number of columns in layout #
- layout: A matrix specifying the layout. If present, 'cols' is ignored. # #
If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), #
then plot 1 will go in the upper left, 2 will go in the upper right, and #
3 will go all the way across the bottom. # multiplot <- function(...,
plotlist=NULL, file, cols=1, layout=NULL) { library(grid) # Make a list
from the ... arguments and plotlist plots <- c(list(...), plotlist)
numPlots = length(plots) # If layout is NULL, then use 'cols' to determine
layout if (is.null(layout)) { # Make the panel # ncol: Number of columns of
plots # nrow: Number of rows needed, calculated from # of cols layout <-
matrix(seq(1, cols * ceiling(numPlots/cols)), ncol = cols, nrow =
ceiling(numPlots/cols)) } if (numPlots==1) { print(plots[[1]]) } else { #
Set up the page grid.newpage() pushViewport(viewport(layout =
grid.layout(nrow(layout), ncol(layout)))) # Make each plot, in the correct
location for (i in 1:numPlots) { # Get the i,j matrix positions of the
regions that contain this subplot matchidx <- as.data.frame(which(layout ==
i, arr.ind = TRUE)) print(plots[[i]], vp = viewport(layout.pos.row =
matchidx$row, layout.pos.col = matchidx$col)) } } }
multiplot(p1, p2, p3, p4, cols=2) # onde p1 p2 etc sao varios plots.
fonte :
http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
Pedro Brasil
Em 12 de maio de 2015 17:00, Alisson Lucrécio <
alisson.lucrecio em ifgoiano.edu.br> escreveu:
> Pedro,
>
> Use o script.
>
> library(ggplot2)
> library(grid)
> library(gridExtra)
>
> graphic1 <- ggplot(......)
> graphic2 <- ggplot(......)
>
> tmp <- ggplot_gtable(ggplot_build(graphic1 ))
> leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
> legend <- tmp$grobs[[leg]]
>
> grid.arrange(arrangeGrob(graphic1 + opts(legend.position="none"),
> graphic2 + opts(legend.position="none")),
> legend, widths=c(9, 0.8), nrow=1)
>
>
> Att.
>
> 2015-05-12 16:34 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil
> [via R-br] <ml-node+s2285057n4664478h54 em n4.nabble.com>:
>
>> Amigos de R,
>>
>> Estou mais uma vez batendo cabeça com o ggplot. Eu gostaria que doi
>> graficos ficasse lado a lado na mesma janela, mas infelizmente ainda estou
>> pensando com o plot.default() e não estou conseguindo. Alguma luz?
>>
>> d <-
>> data.frame(ID=rep(1:10,100),outcome=c(rep(0,500),rep(1,500)),Sex=c(sample(c("F","M"),500,T,c(.8,.2)),sample(c("M","F"),500,T,c(.8,.2))),score=c(rnorm(500,5,10),rnorm(500,20,10)),grave=c("Sim","Não"))
>>
>> library("lme4")
>> fit <- glmer(outcome ~ Sex + score + (1 | ID), data = d, family =
>> binomial,subset=grave=="Sim")
>> summary(fit)
>> fit2 <- glmer(outcome ~ Sex + score + (1 | ID), data = d, family =
>> binomial,subset=grave=="Não")
>> summary(fit2)
>>
>> library("sjPlot")
>> sjp.glmer(fit,type='fe')
>> sjp.glmer(fit2,type='fe')
>>
>> Que a força esteja sempre com voces!
>>
>> Pedro Brasil
>>
>> _______________________________________________
>> R-br mailing list
>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=4664478&i=0>
>> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
>> código mínimo reproduzível.
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the
>> discussion below:
>>
>> http://r-br.2285057.n4.nabble.com/R-br-Como-fazer-para-dois-graficos-do-ggplot-ficarem-lado-a-lado-tp4664478.html
>> To unsubscribe from R-br, click here
>> <http://r-br.2285057.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3357982&code=YWxpc3Nvbi5sdWNyZWNpb0BpZmdvaWFuby5lZHUuYnJ8MzM1Nzk4MnwtNTI1NDI5NDE3>
>> .
>> NAML
>> <http://r-br.2285057.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
>
> --
> Alisson Lucrecio da Costa
>
> _______________________________________________
> R-br mailing list
> R-br em listas.c3sl.ufpr.br
> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
> código mínimo reproduzível.
>
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20150512/74941c22/attachment.html>
Mais detalhes sobre a lista de discussão R-br