0

Data

DATA = data.frame(school = c("A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B"),
                  gender=c("M","M","M","M","F","F","F","F","M","M","M","M","F","F","F","F"),
                  grade = c(10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13),
                  score=c(97,85,95,98,84,90,55,84,52,65,83,75,95,74,76,71))

My try

ggplot(DATA, aes(x=grade, y=score, fill = gender)) + 
  geom_bar(stat= "identity", alpha = 0.3) + 

geom_text(size = 3, position = position_stack(vjust = 0.5))

ggplot(DATA, aes(x=grade, y=score, fill = school)) + 
  geom_bar(stat='identity', position='dodge')

I can do a plot that is stack (see plot number 1) and a plot side by side (see plot number 2) but how do I combine so gender is stacked and compared side by side by school?

bvowe
  • 3,004
  • 3
  • 16
  • 33
  • 2
    Does this help: https://stackoverflow.com/questions/12715635/ggplot2-bar-plot-with-both-stack-and-dodge ? Or this: https://stackoverflow.com/questions/21409850/generate-paired-stacked-bar-charts-in-ggplot-using-position-dodge-only-on-some – markus Mar 24 '19 at 12:08
  • ok I work with this. How I select your answer? – bvowe Mar 24 '19 at 12:23
  • Just consider to upvote the answer from the posted links that helped you solve your problem. – markus Mar 24 '19 at 12:24

0 Answers0