简体   繁体   English

如何从hclust树状图中调整轴标签的余量

[英]How to adjust margin for axis label from hclust dendogram plot

I have the following code: 我有以下代码:

hc <- hclust(dist(USArrests), "ave")
plot(hc)
plot(hc, hang = 0.5, sub="", xlab ="")

Which produce the following plot: 产生以下情节:

在此输入图像描述

As described in the image above. 如上图所示。 How can I push they Height label further right? 我怎样才能push他们的高度标签push 得更进一步?

This can be done using the mgp argument to par : 这可以用做mgp参数par

par(mgp=c(2, 1, 0))
plot(hc, hang = 0.5, sub="", xlab ="")

在此输入图像描述

par(mgp=c(1, 1, 0))
plot(hc, hang = 0.5, sub="", xlab ="")

在此输入图像描述

The other two arguments control the tick marks and the scale position so for instance: 另外两个参数控制刻度线和刻度位置,例如:

par(mgp=c(2, 3, 2))
plot(hc, hang = 0.5, sub="", xlab ="")

在此输入图像描述

A workaround might be to remove the ylab and just add it as text at appropriate coordinates, like this: 解决方法可能是删除ylab,只需将其作为文本添加到适当的坐标,如下所示:

plot(hc, hang = 0.5, sub="", xlab ="", ylab = "")
text(0, -50, "Height", srt = 90)

情节

Maybe the use of mtext could help 也许使用mtext可能有所帮助

plot(hc, hang = 0.5, sub="", xlab ="", ylab = "")
mtext(text = "test", side = 2, line = 2)

yielding this plot 产生这个阴谋

在此输入图像描述

side = 2 defines the lefthand side, and line indicates the "excentricity". side = 2定义左侧,而line表示“偏心”。 You can play around some more with the line and adj parameters (and more) like this: 您可以使用lineadj参数(以及更多)来执行更多操作:

plot(hc, hang = 0.5, sub="", xlab ="", ylab = "")
mtext(text = "t2", side = 2, line = 2, col = "blue")
mtext(text = "t1", side = 2, line = 1, col = "blue")
mtext(text = "t0", side = 2, line = 0, col = "blue")
mtext(text = "tlow", side = 2, line = 0, col = "blue", adj = 0)

yielding the following plot 得出以下情节

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM