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(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]]
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(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 at 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. >
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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 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
<https://sites.google.com/view/francescapancotto/home>
----------------------------------
> Il giorno 3 dic 2019, alle ore 15:03, Rui Barradas <ruipbarradas at
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(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 at 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.
	[[alternative HTML version deleted]]