I have a sample that consists of 2787 rows and 259 columns.
To put this into context, it is a survey of how people in Spain perceive their current economic situation versus the one that was 6 months ago, carried out by a Spanish research institute, CIS.
Thus, I have a column (P3) with 5 answers: "better", "worse", "same", "don't know", and "don't answer". Also, I have another column (P19) with 2 options ("1" for males and "2" for females).
What I would like to get to know is how people rate their current versus past economic situation based on their gender (and plot this). In other words, to see how many males fare their situation "better", how many rate it "worse", and so on; and the same, with females.
To achieve this, I've been trying to run the following code:
CVSPastIndividualSituationMales<- aggregate(CIS$P3 ~ CIS$P19 == "1", CIS, sum)
CVSPastIndividualSituationFemales<- aggregate(CIS$P3 ~ CIS$P19 == "2", CIS, sum)
CurrentVSPastIndividualSituationMales<-ggplot(CIS,mapping=aes(x=CVSPastIndividualSituationMales))+geom_bar(fill="LightGreen")+xlab("Current VS Past Individual Situation for Males")
CurrentVSPastIndividualSituationFemales <-ggplot(CIS,mapping=aes(CVSPastIndividualSituationFemales))+geom_bar(fill="Green") + xlab("Current VS Past Individual Situation for Females")
ggarrange(CurrentVSPastIndividualSituationMales, CVSPastIndividualSituationFemales, ncol = 1, nrow = 1)
However, I get the following error:
Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.
Error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same as the data (2787): x
Backtrace:
1. ggpubr::ggarrange(...)
2. purrr::map(...)
3. ggpubr (local) .f(.x[[i]], ...)
4. cowplot::plot_grid(plotlist = plotlist, ...)
5. cowplot::align_plots(...)
...
16. ggplot2 (local) by_layer(function(l, d) l$compute_aesthetics(d, plot))
17. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
18. l$compute_aesthetics(d, plot)
19. ggplot2 (local) f(..., self = self)
20. ggplot2:::check_aesthetics(evaled, n)
Error in check_aesthetics(evaled, n) :
Does anyone know what I am doing wrong and how I could possible get to the desired outcome?
Many thanks in advance!
P.S. Maybe a Dplyr solution might be available?
