R绘制所有轴标签(防止被跳过) [英] R Draw All Axis Labels (Prevent Some From Being Skipped)

查看:99
本文介绍了R绘制所有轴标签(防止被跳过)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用(axis(1, at=1:27, labels=labs[0:27]))手动添加以下标签时:

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%"  "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%"
[13] "12\n4.2%" ........

我得到以下信息:

如何强制绘制所有标签,以便不跳过1,3,5,6和11? (另外,为了获得额外的荣誉,我如何将整个图像向下移动几个像素?)

How do I force all labels to be drawn so 1,3,5,6, and 11 are not skipped? (also, for extra credit, how do I shift the whole thing down a few pixels?)

推荐答案

?axis告诉您:

该代码会尽力不绘制重叠的刻度标签,因此将省略它们邻接或重叠先前绘制的标签的标签.例如,这可能导致每隔一个刻度线被标记. (刻度线是从左到右或从下到上绘制的,标签之间至少留有一个'm'的大小.)

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

使用cex.axis进行播放,以使标签小到足以容纳它们而不会重叠

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.

这篇关于R绘制所有轴标签(防止被跳过)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆