假设我有这样一个ggplot2树状图:
require(ggplot2)
require(ggdendro)
hc <- hclust(dist(USArrests), "ave")
dhc <- as.dendrogram(hc)
ddata <- dendro_data(dhc, type="rectangle")
ggplot(segment(ddata),labels=rownames(USArrests))+
geom_segment(aes(x=x, y=y, xend=xend, yend=yend))+
theme_dendro()我如何顺时针地在90度旋转它?我在coord_flip()中找到了一些主题,但我只想旋转而不是翻转。我试过geom_segment(aes(x=y, y=x, xend=yend, yend=xend)),但它不起作用。下面是我想要的情节:

发布于 2014-02-26 14:49:16
Y值使用x和xend,y值使用y和yend。使用scale_y_reverse(),您将得到相反的顺序集群。
ggplot(segment(ddata),labels=rownames(USArrests))+
geom_segment(aes(y=x, x=y, yend=xend, xend=yend))+
theme_dendro()+scale_y_reverse()使用原始代码可以实现同样的效果,但加入coord_flip()使其旋转90度,然后添加scale_x_reverse()以得到相反的顺序。
ggplot(segment(ddata),labels=rownames(USArrests))+
geom_segment(aes(x=x, y=y, xend=xend, yend=yend))+
theme_dendro()+coord_flip()+scale_x_reverse()https://stackoverflow.com/questions/22044657
复制相似问题