How to display all x labels in R barplot?

前端 未结 3 1691
有刺的猬
有刺的猬 2020-11-29 02:11

This is a basic question but I am unable to find an answer. I am generating about 9 barplots within one panel and each barplot has about 12 bars. I am providing all the 12 l

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 02:51

    To get rotated labels on a base R barplot, you could (like I do here) adapt one of the examples given in the vignette of the gridBase package:

    library(grid)
    library(gridBase)
    
    ## Make some data with names long enough that barplot won't print them all
    DD <- table(rpois(100, lambda=5))
    names(DD) <- paste("long", names(DD), sep="_")
    
    ## Plot, but suppress the labels
    midpts <- barplot(DD, col=rainbow(20), names.arg="")
    
    ## Use grid to add the labels    
    vps <- baseViewports()
    pushViewport(vps$inner, vps$figure, vps$plot)
    
    grid.text(names(DD),
        x = unit(midpts, "native"), y=unit(-1, "lines"),
        just="right", rot=50)
    
    popViewport(3)
    

    enter image description here

提交回复
热议问题