简体   繁体   中英

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?

This can be done using the mgp argument to 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:

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

情节

Maybe the use of mtext could help

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". You can play around some more with the line and adj parameters (and more) like this:

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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