Rotating x label text in ggplot

前端 未结 1 1064
逝去的感伤
逝去的感伤 2020-12-31 09:54

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


        
1条回答
  •  迷失自我
    2020-12-31 10:29

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

    0 讨论(0)
提交回复
热议问题