r - 减少 barplot 中 names.arg 和轴(框)之间的空间
问题描述
我创建了一个barplot
被一个盒子包围的简单对象。有什么办法可以让我的名字更靠近盒子(蓝色标记的空间)?
MWE:
set.seed(1)
count <- runif(n = 3, min = 0, max = 10)
names <- letters[seq(from = 1, to = 3)]
barplot(height = count,
names.arg = names,
horiz = TRUE,
las = 1)
box()
解决方案
这里有两种方法可以做到这一点。您可以使用rect
而不是box
将框边界向左移动:
barplot(height=count, names.arg=names, horiz=TRUE, las=1)
bounds <- par("usr")
rect(bounds[1]-.1, bounds[3], bounds[2], bounds[4], xpd=NA)
或者您可以单独添加 y 轴,这样您就可以控制标签的绘制位置:
x <- barplot(height=count, horiz=TRUE, las=1)
box()
axis(2, x, names, las=1, tick=FALSE, mgp=c(2, .35, 0))
调整中间值mgp
以定位标签(请参阅?par
)
推荐阅读
- r - 将第二个数据框中的数据标签添加到包含 geom_path() 的 ggplot
- javascript - 检查对象数组是否包含多个对象
- amazon-web-services - AWS SAM HttpApiGateway Lambda 授权方:授予调用 Lambda 的权限
- swift - Swift Package - 使用 bundle 分发独立的可执行文件
- javascript - CanvaJs:给定数组中的前 10 个(排序的)元素
- php - 从数据库中删除一行后,有没有办法在 MYSQL 中自动递增?
- docker-compose - docker-compose:不接受以“x-”开头的扩展名(无效的顶级属性“x-...”)
- javascript - 如何防止网站因不活动而将您注销
- http - 重定向后如何获取lighttpd服务器地址?
- php - 如何分解要在图像标签中使用的字符串