R Draw All Axis Labels (Prevent Some From Being Skipped)

后端 未结 6 1153
不思量自难忘°
不思量自难忘° 2020-12-09 10:20

When I manually add the following labels with (axis(1, at=1:27, labels=labs[0:27])):

> labs[0:27]
 [1] \"0\\n9.3%\"  \"1\\n7.6%\"  \"2\\n5.6%         


        
6条回答
  •  佛祖请我去吃肉
    2020-12-09 10:52

    ?axis tells you that:

    The code tries hard not to draw overlapping tick labels, and so will omit labels where they would abut or overlap previously drawn labels. This can result in, for example, every other tick being labelled. (The ticks are drawn left to right or bottom to top, and space at least the size of an ‘m’ is left between labels.)

    Play with cex.axis so that labels are small enough to fit without overlapping

    labs <-c("0\n9.3%","1\n7.6%","2\n5.6%","3\n5.1%","4\n5.7%","5\n6.5%","6\n7.3%",
             "7\n7.6%","8\n7.5%","9\n7%", "10\n6.2%","11\n5.2%","12\n4.2%",12:27)
    plot(1:27,xaxt = "n")
    axis(side=1, at=1:27, labels=labs[0:27],cex.axis=0.35)
    

    If you widen you graph (manually by dragging or programmatically), you can increase the size of your labels.

提交回复
热议问题