[R] Two geom_bar with counts to put in the same plot

Francesca |r@nce@c@@p@ncotto @end|ng |rom gm@||@com
Wed Dec 4 15:27:35 CET 2019


Hi!
It is not exactly what I wanted but more than I suspected I could get.
Thanks a lot, this is awesome!
Francesca

On Wed, 4 Dec 2019 at 14:04, Rui Barradas <ruipbarradas using sapo.pt> wrote:

> Hello,
>
> Please keep R-Help in the thread.
>
> As for the question, the following divides by facets, participation1/2
> with values 0/1. See if that's what you want.
>
>
> idv <- grep("part", names(DB)[-(3:4)], ignore.case = TRUE, value = TRUE)
> dblong <- reshape2::melt(DB[-(3:4)], id.vars = idv)
> dblong <- reshape2::melt(dblong, id.vars = c("variable", "value"))
> names(dblong) <- c("deltaVar", "delta", "participationVar",
> "participation")
> dblong <- dblong[complete.cases(dblong),]
>
> ggplot(dblong, aes(x = delta, fill = deltaVar)) +
>    geom_density(aes(alpha = 0.2)) +
>    scale_alpha_continuous(guide = "none") +
>    facet_wrap(participationVar ~ participation)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 08:25 de 04/12/19, Francesca escreveu:
> > Dear  Rui
> > the code works and the final picture is aesthetical as I wanted(very
> > beautiful indeed), but I probably did not explain that the two
> > distributions that I want to overlap, must be different by participation
> > 1 and participation 2, which are to dummy variables that identify :
> > Participation 1(equivalent to PARTICIPATIONNOPUN): 1 participants, 0 non
> > participants, for the variable delta11_L
> > Participation 2(equivalent to PARTICIPATIONPUN): 1 participants, 0 non
> > participants, for the variable delta2_L
> >
> > The density plots are four in the end rather than 2: I compare delta11_L
> > for Participants1 vsnon participants and delta2_L for Participants 2 vs
> > non Participants 2,
> > I basically want to verify whether the population of Participants vs Non
> > participants, change going from delta11_L to delta2_L
> >
> >
> > Sorry for being unclear.
> > Thanks for any help.
> > Francesca
> >
> > On Wed, 4 Dec 2019 at 09:16, Rui Barradas <ruipbarradas using sapo.pt
> > <mailto:ruipbarradas using sapo.pt>> wrote:
> >
> >     Hello,
> >
> >     Is it as simple as this? The code below does not separate the
> >     participant1 and participant2, only the 'delta' variables.
> >
> >
> >     idv <- grep("part", names(DB)[-(3:4)], ignore.case = TRUE, value =
> TRUE)
> >     dblong <- reshape2::melt(DB[-(3:4)], id.vars = idv)
> >     head(dblong)
> >
> >     ggplot(dblong, aes(x = value, fill = variable)) +
> >         geom_density(aes(alpha = 0.2)) +
> >         scale_alpha_continuous(guide = "none")
> >
> >
> >     I will also repost the data, since you have posted a matrix and this
> >     code needs a data.frame.
> >
> >
> >     DB <-
> >     structure(list(participation1 = c(1, 1, 1, 1, 1, 1, 1, 1, 1,
> >     1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >     1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >     1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
> >     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
> >     1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >     1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >     1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >     1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), participation2 = c(1,
> >     1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
> >     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
> >     0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1,
> >     1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
> >     1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1,
> >     1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1,
> >     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1,
> >     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
> >     1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
> >     1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
> >     0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >     1, 1, 1, 1), ParticipantsNOPUN = structure(c(2L, 2L, 2L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >     2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >     1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L,
> >     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, NA, NA, NA, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >     NA, NA, NA, NA, NA, NA, NA, NA), .Label = c("1", "2"), class =
> >     "factor"),
> >           ParticipantsPUN = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 1L,
> >           2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L,
> >           2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >           1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >           1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L,
> >           1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L,
> >           2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L,
> >           1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,
> >           1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L,
> >           1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L,
> >           2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >           2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >           2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >           1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,
> >           1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L,
> >           2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> >           2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"),
> >           delta11_L = c(0, -10, -10, 0, 0, 0, -30, 0, 10, 0, 20, 10,
> >           0, 0, 20, 0, 0, -10, 30, 10, 0, 0, 0, 0, 10, 0, 0, 0, 0,
> >           0, 0, 0, 0, -10, 0, 0, 0, 40, -10, 0, 10, 0, 10, 0, -20,
> >           0, 0, 0, 10, -20, 10, -10, 40, -10, -10, 10, 20, 10, 0, 0,
> >           0, 0, 0, 0, -10, 0, 0, 20, 0, 0, 0, 0, 10, 0, 0, 0, 10, 0,
> >           -10, 10, 0, 0, 10, 10, 10, 0, 0, 0, 0, 0, -10, 0, 0, 0, 20,
> >           0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 10, 0, 10, 0, 0, 0, 20, -20,
> >           0, 0, -10, 0, 0, 0, 0, -10, 10, 0, 20, 0, 0, 0, 0, 0, -10,
> >           0, 0, 0, 0, 0, -10, 0, 0, -10, 0, -10, 30, -10, 0, 0, 10,
> >           -10, 0, -10, -10, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0,
> >           10, 10, 0, 0, -20, -10, 0, 0, 0, 0, 0, 0, 10, 30, 40, 30,
> >           30, 30, 30, 20, 20, 40, 20, 20, 10, 20, 30, 20, 40, 20, 30,
> >           20, 30, 20, 20, 30, 20, 40, 10, 20, 10, 30, 30, 30, 30, 10,
> >           30, 30, 20, 10, 40, 30, 40, 40, 30, 20, 10, 10, 20, 20, 30,
> >           40, 40, 40, 40, 0, 20, 20, 40, 10, 20, 20, 10), delta2_L = c(0,
> >           -10, 0, 0, 0, 0, 30, 10, 40, 0, 0, 0, 0, 0, 10, 0, 0, 30,
> >           10, 10, 0, 0, -10, -20, -10, 0, 0, 0, -10, 10, 0, 40, 0,
> >           30, 0, 10, 0, 40, 0, 0, -10, 0, 10, 40, -10, 0, 0, 0, 10,
> >           0, 10, -10, 40, 10, 20, 10, 40, 0, 10, -10, 0, 40, 0, 0,
> >           -10, 0, 0, 20, -10, 0, 10, 0, 30, -10, 0, 0, 0, -10, 40,
> >           10, 10, 0, 10, -10, 0, 10, 0, 10, 0, -20, 20, 0, 0, -20,
> >           20, 0, -30, 20, 0, 0, 20, 10, 0, 20, 30, 0, 0, -10, 10, 10,
> >           0, -10, 40, 10, 0, 10, 0, 0, 20, 10, 20, 30, 0, 40, 30, 0,
> >           20, 40, -10, 0, 0, 0, -10, 0, 20, -10, 0, 0, 10, 0, 0, 20,
> >           -20, -20, 0, 20, 0, 0, 10, 0, -10, -10, 20, -10, 0, 0, 0,
> >           0, 0, 0, 0, -10, 30, 10, 0, 0, 10, 20, 10, -10, 10, 0, 0,
> >           -10, 30, -20, 10, 0, 0, 0, 10, 10, 10, 10, -10, 0, 20, 10,
> >           10, 10, 0, -10, -10, 0, 0, 10, 20, 0, -10, 10, 0, 10, 20,
> >           10, 0, 0, 0, 0, 10, 10, 10, 30, 10, 0, 0, -10, 40, 0, 0,
> >           10, 10, 40, 30, -10, 0, 0, 10, 20, 0, 0, 10, 40, 0, 0, -10,
> >           -20)), row.names = c(NA, -236L), class = "data.frame")
> >
> >
> >     Hope this helps,
> >
> >     Rui Barradas
> >
> >
> >
> >     Às 14:10 de 03/12/19, Francesca escreveu:
> >      > Hi
> >      > here it is;. THANKS!
> >      >
> >      > dput(DATASET)
> >      > structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
> >      > 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
> >      > 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA, NA, NA, NA, NA, NA, NA,
> >      > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >      > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >      > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >      > NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1,
> >      > 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >      > 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1,
> >      > 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> >      > 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0,
> >      > 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1,
> >      > 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
> >      > 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
> >      > 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
> >      > 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
> >      > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
> >      > 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, NA,
> >      > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >      > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >      > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >      > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2, 2, 2, 2, 2, 2,
> >      > 1, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2,
> >      > 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 1, 2, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 2, 2, 2, 1, 2,
> >      > 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> >      > 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
> >      > 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2,
> >      > 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
> >      > -10, -10, 0, 0, 0, -30, 0, 10, 0, 20, 10, 0, 0, 20, 0, 0, -10,
> >      > 30, 10, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, -10, 0, 0, 0,
> >      > 40, -10, 0, 10, 0, 10, 0, -20, 0, 0, 0, 10, -20, 10, -10, 40,
> >      > -10, -10, 10, 20, 10, 0, 0, 0, 0, 0, 0, -10, 0, 0, 20, 0, 0,
> >      > 0, 0, 10, 0, 0, 0, 10, 0, -10, 10, 0, 0, 10, 10, 10, 0, 0, 0,
> >      > 0, 0, -10, 0, 0, 0, 20, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 10, 0,
> >      > 10, 0, 0, 0, 20, -20, 0, 0, -10, 0, 0, 0, 0, -10, 10, 0, 20,
> >      > 0, 0, 0, 0, 0, -10, 0, 0, 0, 0, 0, -10, 0, 0, -10, 0, -10, 30,
> >      > -10, 0, 0, 10, -10, 0, -10, -10, 0, 10, 0, 0, 0, 0, 0, 0, 0,
> >      > 0, 10, 0, 0, 10, 10, 0, 0, -20, -10, 0, 0, 0, 0, 0, 0, 10, 30,
> >      > 40, 30, 30, 30, 30, 20, 20, 40, 20, 20, 10, 20, 30, 20, 40, 20,
> >      > 30, 20, 30, 20, 20, 30, 20, 40, 10, 20, 10, 30, 30, 30, 30, 10,
> >      > 30, 30, 20, 10, 40, 30, 40, 40, 30, 20, 10, 10, 20, 20, 30, 40,
> >      > 40, 40, 40, 0, 20, 20, 40, 10, 20, 20, 10, 0, -10, 0, 0, 0, 0,
> >      > 30, 10, 40, 0, 0, 0, 0, 0, 10, 0, 0, 30, 10, 10, 0, 0, -10, -20,
> >      > -10, 0, 0, 0, -10, 10, 0, 40, 0, 30, 0, 10, 0, 40, 0, 0, -10,
> >      > 0, 10, 40, -10, 0, 0, 0, 10, 0, 10, -10, 40, 10, 20, 10, 40,
> >      > 0, 10, -10, 0, 40, 0, 0, -10, 0, 0, 20, -10, 0, 10, 0, 30, -10,
> >      > 0, 0, 0, -10, 40, 10, 10, 0, 10, -10, 0, 10, 0, 10, 0, -20, 20,
> >      > 0, 0, -20, 20, 0, -30, 20, 0, 0, 20, 10, 0, 20, 30, 0, 0, -10,
> >      > 10, 10, 0, -10, 40, 10, 0, 10, 0, 0, 20, 10, 20, 30, 0, 40, 30,
> >      > 0, 20, 40, -10, 0, 0, 0, -10, 0, 20, -10, 0, 0, 10, 0, 0, 20,
> >      > -20, -20, 0, 20, 0, 0, 10, 0, -10, -10, 20, -10, 0, 0, 0, 0,
> >      > 0, 0, 0, -10, 30, 10, 0, 0, 10, 20, 10, -10, 10, 0, 0, -10, 30,
> >      > -20, 10, 0, 0, 0, 10, 10, 10, 10, -10, 0, 20, 10, 10, 10, 0,
> >      > -10, -10, 0, 0, 10, 20, 0, -10, 10, 0, 10, 20, 10, 0, 0, 0, 0,
> >      > 10, 10, 10, 30, 10, 0, 0, -10, 40, 0, 0, 10, 10, 40, 30, -10,
> >      > 0, 0, 10, 20, 0, 0, 10, 40, 0, 0, -10, -20), .Dim = c(236L, 6L
> >      > ), .Dimnames = list(NULL, c("participation1", "participation2",
> >      > "ParticipantsNOPUN", "ParticipantsPUN", "delta11_L", "delta2_L"
> >      > )))
> >      >
> >      >
> >      >
> >      >
> >      >
> >      > Francesca Pancotto
> >      > ----------------------------------
> >      > Francesca Pancotto, PhD
> >      > Associate Professor of Political Economy
> >      > Università di Modena e Reggio Emilia
> >      > Viale A. Allegri, 9
> >      > 40121 Reggio Emilia
> >      > Office: +39 0522 523264
> >      > Web:
> >      > https://sites.google.com/view/francescapancotto/home
> >      >
> >      > ----------------------------------
> >      >
> >      >> Il giorno 3 dic 2019, alle ore 15:03, Rui Barradas
> >      >> <ruipbarradas using sapo.pt <mailto:ruipbarradas using sapo.pt>
> >     <mailto:ruipbarradas using sapo.pt <mailto:ruipbarradas using sapo.pt>>> ha
> scritto:
> >      >>
> >      >> Hello,
> >      >>
> >      >> Please post the output of
> >      >>
> >      >> dput(DB)
> >      >>
> >      >> in a next e-mail to R-Help, like this it's difficult for us to
> >     use the
> >      >> data you posted.
> >      >>
> >      >> And yes, I bet you will need the data in long format. It is a
> >     frequent
> >      >> first step to the problem of plotting two or more columns in the
> >     same
> >      >> graph. To say more only with data.
> >      >>
> >      >>
> >      >> Hope this helps,
> >      >>
> >      >> Rui Barradas
> >      >>
> >      >> Às 09:18 de 03/12/19, Francesca escreveu:
> >      >>> Dear Contributors,
> >      >>> I would like to ask help on how to create a  plot that is the
> >     overlapping
> >      >>> of two other plots.
> >      >>> It is a geom_bar structure, where I want to count the
> >     occurrences of two
> >      >>> variables, participation1 and participation2 that I recoded as
> >     factors as
> >      >>> ParticipationNOPUN and ParticipationPUN to have nice names in
> >     the legend.
> >      >>> The variables to "count" in the two plots are delta11_L and
> >     delta2_L
> >      >>> These are my data and code to create the two plots. I would
> >     like to put
> >      >>> them in the same plot as superimposed areas so that I see the
> >     change
> >      >>> in the
> >      >>> distribution of counts in the two cases.
> >      >>> This is DB:
> >      >>> participation1 participation2 ParticipantsNOPUN ParticipantsPUN
> >     delta11_L
> >      >>> delta2_L
> >      >>>   [1,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>   [2,]              1              1                 2
> >                    2
> >      >>>   -10      -10
> >      >>>   [3,]              1              1                 2
> >                    2
> >      >>>   -10        0
> >      >>>   [4,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>   [5,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>   [6,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>   [7,]              1              0                 2
> >                    1
> >      >>>   -30       30
> >      >>>   [8,]              1              1                 2
> >                    2
> >      >>>     0       10
> >      >>>   [9,]              1              0                 2
> >                    1
> >      >>>    10       40
> >      >>>  [10,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [11,]              0              0                 1
> >                    1
> >      >>>    20        0
> >      >>>  [12,]              1              1                 2
> >                    2
> >      >>>    10        0
> >      >>>  [13,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [14,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [15,]              1              1                 2
> >                    2
> >      >>>    20       10
> >      >>>  [16,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [17,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [18,]              1              1                 2
> >                    2
> >      >>>   -10       30
> >      >>>  [19,]              0              0                 1
> >                    1
> >      >>>    30       10
> >      >>>  [20,]              1              1                 2
> >                    2
> >      >>>    10       10
> >      >>>  [21,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [22,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [23,]              1              1                 2
> >                    2
> >      >>>     0      -10
> >      >>>  [24,]              1              1                 2
> >                    2
> >      >>>     0      -20
> >      >>>  [25,]              1              1                 2
> >                    2
> >      >>>    10      -10
> >      >>>  [26,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>>  [27,]              1              1                 2
> >                    2
> >      >>>     0        0
> >      >>> First PLOT(I need to subset the data to eliminate some NA. NB:
> >     the two
> >      >>> dataframes end up not having the same number of rows for this
> >     reason):
> >      >>> ggplot(data=subset(DB, !is.na <http://is.na>(participation1)),
> >     aes(x = delta11_L, fill
> >      >>> =ParticipantsNOPUN))+
> >      >>>          geom_bar(position = "dodge")+ theme_bw(base_size = 12)
> +
> >      >>> labs(x="Delta Contributions (PGG w/out punishment)")+
> >      >>>   theme(legend.position = "top",legend.title = element_blank())
> >      >>> +scale_fill_brewer(palette="Set1")
> >      >>> Second PLOT:
> >      >>>  ggplot(DB, aes(x = delta2_L, fill =ParticipantsPUN)  , aes(x =
> >     delta2_L,
> >      >>> fill =ParticipantsPUN))+
> >      >>>   geom_bar(position = "dodge")+ theme_bw(base_size = 12) +
> >     labs(x="Delta
> >      >>> Contributions (PGG w/punishment)")+
> >      >>>   theme(legend.position = "top",legend.title = element_blank())
> >      >>> +scale_fill_brewer(palette="Set1")
> >      >>> is it possible to create a density plot of the two counts data
> >     on the
> >      >>> same
> >      >>> plot?
> >      >>> Do I need to create a variable count or long data format?
> >      >>> Thanks
> >      >>> [[alternative HTML version deleted]]
> >      >>> ______________________________________________
> >      >>> R-help using r-project.org <mailto:R-help using r-project.org>
> >     <mailto:R-help using r-project.org <mailto:R-help using r-project.org>> mailing
> >     list -- To
> >      >>> UNSUBSCRIBE and more, see
> >      >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >      >>> PLEASE do read the posting guide
> >      >>> http://www.R-project.org/posting-guide.html
> >      >>> and provide commented, minimal, self-contained, reproducible
> code.
> >      >
> >
> >
> >
> > --
> >
> > Francesca
> >
> > ----------------------------------
> > Francesca Pancotto, PhD
> > Università di Modena e Reggio Emilia
> > Viale A. Allegri, 9
> > 40121 Reggio Emilia
> > Office: +39 0522 523264
> > Web: https://sites.google.com/view/francescapancotto/home
> > <https://sites.google.com/site/francescapancotto/>
> > ----------------------------------
>


-- 

Francesca

----------------------------------
Francesca Pancotto, PhD
Università di Modena e Reggio Emilia
Viale A. Allegri, 9
40121 Reggio Emilia
Office: +39 0522 523264
Web: https://sites.google.com/view/francescapancotto/home
<https://sites.google.com/site/francescapancotto/>
----------------------------------

	[[alternative HTML version deleted]]



More information about the R-help mailing list