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

后端 未结 6 1162
不思量自难忘°
不思量自难忘° 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:48

    I had a similar problem where I wanted to stagger the labels and get them to print without losing some. I created two sets of ticks showing second set below the other to make it look as if it staggers.

    xaxis_stagger = function(positions,labels) {
      odd=labels[seq(1,length(labels),2)]
      odd_pos=positions[seq(1,length(positions),2)]
      even=labels[seq(2,length(labels),2)]  
      even_pos=positions[seq(2,length(positions),2)]
      axis(side=1,at=odd_pos,labels=odd)
      axis(side=1,at=even_pos,labels=even,padj=1.5)
    }
    

    So you give the positions where you want the ticks to be and the labels for those ticks and this would then re-organise it into two sets of axis and plot them on the original plot. Original plot would be done with xaxt="n".

提交回复
热议问题