Search code examples
rplotfrequency

Frequency Plot with 2 classes in R


I have a dataframe with 2 features, the first one is the Classe 'Yes' or 'No', the second one is "JobSatisfaction". I want to plot something like this.

https://i.sstatic.net/oWzV1.png

Where I count the frequency of each value of the variable JobSatisfaction and I color the different classes.

image source


Solution

  • library(ggplot2)
    ggplot(your_data, aes(x = JobSatisfaction, fill = Class)) %>%
      geom_bar()
    

    You can play with the position argument of geom_bar(), as described here.