在使用堆积条形图时候,新增一个百分比堆积条形图,可以加深读者印象。

封装一个function函数后只需要在调用的数据上改一下pos=‘fill’的代码即可。比较方便。

案例:

# 封装函数
fun1<-function(data,xlab,fillc,pos,xname,yname){
  ggplot(data,aes(x=xlab,fill=fillc))+
    geom_bar(position = pos)+
    labs(x=xname,y=yname)+
    coord_flip()+
    theme_minimal()
}
# 探索不同教育程度的学生的课程主题(pos=‘stack’指定使用堆积条形图)
p1<-fun1(student_data,student_data$Topic,fillc = student_data$StageID,pos='stack',xname='Topic',yname='student count')
p2<- fun1(student_data,student_data$Topic,fillc = student_data$StageID,pos='fill',xname='Topic',yname='student count')
multiplot(p1,p2)

R语言 绘图——条形图可以将堆积条形图与百分比堆积条形图配合使用

 

相关文章:

  • 2021-10-02
  • 2021-09-16
  • 2021-07-12
  • 2021-05-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-19
猜你喜欢
  • 2022-12-23
  • 2021-11-03
  • 2021-12-11
  • 2021-06-20
  • 2021-12-04
  • 2021-10-18
相关资源
相似解决方案