Histogram for two variables in one chart

I have to develop a histogram for two variables in one chart. i am trying to use table() function to combine them but its not the chart i expect
Here is the code:
table <- table(Agency_Turnover_by_Reason_Code_FY18$Resignation,Agency_Turnover_by_Reason_Code_FY18$Retirement)
hist(table,
main = " Histogram of Resignation vs Retirement",
xlab = "Resignation",
border = "black",
col = "blue")

Have you considered using ggplot? Then you can create the two histograms using the facet_wrap function.

library(ggplot)
library(tidyr)
df <- Agency_Turnover_by_Reason_Code_FY18 %>% 
  pivot_longer(everything())
ggplot(data = df) +
  geom_histogram(mapping = aes(x = value)) +
  facet_wrap(vars(name))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.