R 如何旋转ggplot2树状图?

R 如何旋转ggplot2树状图?,r,ggplot2,R,Ggplot2,假设我有一个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,

假设我有一个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()
require(ggplot2)
需要(GGO)

hc对y值使用
x
xend
,然后对y值使用
y
yend
。使用
scale\u y\u reverse()

ggplot(segment(ddata),labels=rownames(USArrests))+ 
  geom_segment(aes(y=x, x=y, yend=xend, xend=yend))+ 
  theme_dendro()+scale_y_reverse()
同样可以使用原始代码实现,但添加
coord\u flip()
旋转90度,然后添加
scale\u x\u 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()

对y值使用
x
xend
,然后对y值使用
y
yend
。使用
scale\u y\u reverse()

ggplot(segment(ddata),labels=rownames(USArrests))+ 
  geom_segment(aes(y=x, x=y, yend=xend, xend=yend))+ 
  theme_dendro()+scale_y_reverse()
同样可以使用原始代码实现,但添加
coord\u flip()
旋转90度,然后添加
scale\u x\u 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()