0

Hi I have a table like this:

Question Age_Group Value
Question 1 10-20 15
Question 2 10-20 16
Question 3 10-20 12
.....
Question 1 20-30 13
Question 2 20-30 15
Question 3 20-30 18

I want to build a histogram where questions are in y - axis, age groups in x - axis and by bars the comparision is visible based on Value column.

How to make this possible? Regards

user1997567
  • 439
  • 4
  • 19
  • Could you provide a reproducible example with your code? Check this thread and the `dput` option https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Rhesous Aug 05 '20 at 14:20
  • Hi @Arault. Actually I cannot provide ggplot code for this plot because that is what I am thinking about – user1997567 Aug 05 '20 at 14:21
  • Could you add the dput output of your dataset then? So we can try with your data without having to manually copy the dataframe – Rhesous Aug 05 '20 at 14:23

1 Answers1

2

Do you want facets? E.g. something like this:

set.seed(123)
DF <- data.frame(Question = rep(paste0("Question ", 1:10), 80),
  Age_Group = factor(sample(c("10-20", "20-30", "30-40", "40-50"), 
    800, replace=TRUE)),
  Value = sample(8:30, 800, replace = TRUE))
DF$Question <- factor(DF$Question, unique(DF$Question))

library(ggplot2)  
ggplot(DF, aes(x=Value)) + 
  geom_histogram() +
  facet_grid(Question ~ Age_Group) +
  theme(strip.text.y = element_text(angle = 0))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2020-08-05 by the reprex package (v0.3.0)

user12728748
  • 8,106
  • 2
  • 9
  • 14