旋转ggplot中的x标签文本 [英] Rotating x label text in ggplot

查看:131
本文介绍了旋转ggplot中的x标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码应该旋转并在x轴上对齐文本标签,但是由于某些原因,它不会:

The code below should rotate and align the text labels on the x-axis, but for some reason it don't:

ggplot(res, aes(x=TOPIC,y=count), labs(x=NULL)) + 
  scale_y_continuous(limits=c(0,130),expand=c(0,0)) +
  scale_x_discrete("",labels=c("ANA"="Anatomy","BEH"="Behavior","BOUND"="Boundaries",
                           "CC"="Climate change","DIS"="Disease","EVO"="Evolution",
                           "POPSTAT"="Pop status","POPABU"="Pop abundance",
                           "POPTR"="Pop trend","HARV"="Harvest","HAB"="Habitat",
                           "HABP"="Habitat protection","POLL"="Pollution",
                           "ZOO"="Captivity","SHIP"="Shipping","TOUR"="Tourism",
                           "REPEC"="Reprod ecology","PHYS"="Physiology","TEK"="TEK",
                           "HWC"="HWC","PRED"="Predator-prey","METH"="Methods",
                           "POPGEN"="Pop genetics","RESIMP"="Research impact",
                           "ISSUE"="Other","PROT"="Protection","PA"="Protected areas",
                           "PEFF"="Protection efficiency","MINOR"="Minor")) + 
  theme(axis.text.x=element_text(angle=90,hjust=1)) +
  geom_bar(stat='identity') +
  theme_bw(base_size = 16) +
  ggtitle("Peer-reviewed papers per topic")

推荐答案

您需要更改图层的顺序,否则theme_bw将覆盖theme:

You need to change the order of the layers, otherwise theme_bw will override theme:

ggplot(res, aes(x=TOPIC,y=count), labs(x=NULL)) + 
  scale_y_continuous(limits=c(0,130),expand=c(0,0)) +
  scale_x_discrete("",labels=c("ANA"="Anatomy","BEH"="Behavior","BOUND"="Boundaries",
                           "CC"="Climate change","DIS"="Disease","EVO"="Evolution",
                           "POPSTAT"="Pop status","POPABU"="Pop abundance",
                           "POPTR"="Pop trend","HARV"="Harvest","HAB"="Habitat",
                           "HABP"="Habitat protection","POLL"="Pollution",
                           "ZOO"="Captivity","SHIP"="Shipping","TOUR"="Tourism",
                           "REPEC"="Reprod ecology","PHYS"="Physiology","TEK"="TEK",
                           "HWC"="HWC","PRED"="Predator-prey","METH"="Methods",
                           "POPGEN"="Pop genetics","RESIMP"="Research impact",
                           "ISSUE"="Other","PROT"="Protection","PA"="Protected areas",
                           "PEFF"="Protection efficiency","MINOR"="Minor")) + 
  theme_bw(base_size = 16) +
  theme(axis.text.x=element_text(angle=90,hjust=1)) +
  geom_bar(stat='identity') +
  ggtitle("Peer-reviewed papers per topic")

这篇关于旋转ggplot中的x标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆