How to display all x labels in R barplot?

前端 未结 3 1690
有刺的猬
有刺的猬 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 03:02

    R won't label every bar if the labels are too big.

    I would suggest trying to rotate the labels vertically by passing in the las=2 argument to your plotting function.

    If the labels are still too large, you can try shrinking the font by using the cex.names=.5 argument.

    Sample Data for plot

    sample_curve <- c(2.31,2.34,2.37,2.52,2.69,2.81,2.83,2.85,2.94, 3.03,  3.21,  3.33)   # create a sample curve
    names(sample_curve)<-c("1 MO","2 MO","3 MO","6 MO","1 YR","2 YR","3 YR","5 YR","7 YR","10 YR","20 YR","30 YR") # label the curve
    

    Example of plot with labels too big

    barplot(sample_curve) # labels too big for the plot
    

    Example of plot with labels rotated and small

    barplot(sample_curve, las=2, cex.names=.5) # lables are rotated and smaller, so they fit
    

提交回复
热议问题