R Box并排和堆叠

时间:2019-03-24 12:03:16

标签: r ggplot2 box

数据

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))

我的尝试

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

geom_text(大小= 3,位置= position_stack(垂直= 0.5))

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

我可以做一个堆积图(请参见图号1)和一个并排图(请参见图号2),但是如何结合起来使性别堆叠起来并在学校中并排比较呢?

0 个答案:

没有答案