2017-04-01 92 views
4

如所示,如果圖是徑向的,則無論是否使用repel=T,標籤都可能擁擠。如何讀取ggraph徑向圖中的文本標籤

有沒有辦法讓標籤交互或允許旋轉圖形以讀取標籤?

library(ggraph) 
mtcarsDen <- as.dendrogram(hclust(dist(mtcars[1:4], method='euclidean'), 
          method='ward.D2')) 
ggraph(graph = mtcarsDen, layout = 'dendrogram', repel = TRUE, circular = TRUE, 
    ratio = 0.5) + 
geom_edge_elbow() + 
geom_node_text(aes(x = x*1.05, y=y*1.05, filter=leaf, 
       angle = node_angle(x, y), label = label), 
      size=3, hjust='outward') + 
geom_node_point(aes(filter=leaf)) + 
coord_fixed() + 
ggforce::theme_no_axes() 

回答

1

您可以修改您的視角中的審美是這樣的:

ggraph(graph = mtcarsDen, layout = 'dendrogram', repel = TRUE, circular = TRUE, 
     ratio = 0.5) + 
    geom_edge_elbow() + 
    geom_node_text(aes(x = x*1.005, y=y*1.005, filter=leaf, 
        angle = -((-node_angle(x, y)+90)%%180)+90, label = label), 
       size=3, hjust='outward') + 
    geom_node_point(aes(filter=leaf)) + 
    coord_fixed() + 
    ggforce::theme_no_axes() 

enter image description here