我正在运行一些集群分析,我正在使用 pvclust,如下所示:
d.pv <- pvclust(t(mtcars), method = "euclidean",
method.hclust = "complete", nboot = 10)
plot(d.pv)
我想编辑图表并删除红色、绿色数字和灰色数字。我还想根据特定列在 x 轴上着色标签mtcars$cyl
要删除红色、绿色和灰色数字,请使用以下命令:
plot(d.pv, print.num = FALSE, print.pv = FALSE)
为标签着色在plot.pvclust
. 我建议将其转换ggplot2
为更大的灵活性。
# Run pvclust and restructure data
d.pv <- as.dendrogram(pvclust(t(mtcars), method = "euclidean",
method.hclust = "complete", nboot = 10)$hclust)
ddata <- dendro_data(d.pv, type = "rectangle")
# Get data frames to plot
df_seg <- segment(ddata)
df_labs <- data.frame(label(ddata), cyl = as.factor(mtcars[match(label(ddata)$label, rownames(mtcars)), "cyl"]))
# Create ggplot dendrogram
p <- ggplot()
p <- p + geom_segment(data = df_seg,
aes(x = x, y = y, xend = xend, yend = yend),
size = 1.25,
colour = "darkgray",
lineend = "round")
p <- p + geom_text(data = df_labs,
aes(x = x,
y = y,
label = label,
colour = cyl),
nudge_y = -10,
family = "serif",
size = 5,
angle = 90,
hjust = 1)
p <- p + xlab("") + ylab("Height")
p <- p + theme(axis.line.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
text = element_text(family = "serif"))
p <- p + scale_y_continuous(expand = expand_scale(add = c(85, 0)))
p