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

时间:2018-03-27 08:45:38

标签: r plot

我有以下代码:

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

产生以下情节:

enter image description here

如上图所示。我怎样才能push他们身高标签更正确?

3 个答案:

答案 0 :(得分:1)

这可以使用par的{​​{1}}参数来完成:

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

enter image description here

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

enter image description here

其他两个参数控制刻度线和刻度位置,例如:

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

enter image description here

答案 1 :(得分:0)

解决方法可能是删除ylab并将其作为文本添加到适当的坐标处,如下所示:

select distinct EQMFSN, WONO
from t
where t.date = (select min(t2.DOCDT8) from t t2);

Plot

答案 2 :(得分:0)

也许使用mtext可以提供帮助

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

产生这个情节

enter image description here

side = 2定义左侧,line表示&#34;偏离度&#34;。您可以使用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)

产生以下情节

enter image description here