[R] Two geom_bar with counts to put in the same plot
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Tue Dec 3 15:03:32 CET 2019
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 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.
>
More information about the R-help
mailing list