[英]pvclust edit dendogram graph
I'm running some cluster analysis and I'm using pvclust as showed below: 我正在运行一些聚类分析,并且正在使用pvclust,如下所示:
d.pv <- pvclust(t(mtcars), method = "euclidean",
method.hclust = "complete", nboot = 10)
plot(d.pv)
I want to edit the graph and remove red, green numbers, and grey numbers. 我想编辑图形并删除红色,绿色和灰色数字。 Also I want to color label on x axis according to aa specific column
mtcars$cyl
我也想根据一个特定的列
mtcars$cyl
在x轴上标记标签
To remove the red, green, and grey numbers use the following: 要删除红色,绿色和灰色数字,请执行以下操作:
plot(d.pv, print.num = FALSE, print.pv = FALSE)
Colouring the labels is trickier within the confines of plot.pvclust
. 在
plot.pvclust
的范围内,给标签plot.pvclust
。 I'd suggest converting it into ggplot2
for more flexibility. 我建议将其转换为
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.