我正在尝试绘制二元组的共现(来自Text Mining with R),如下所示:
但是按照书中给出的完全相同的代码,我的情节缺少很多线条和颜色。不知道是因为我错过了一些重要步骤还是我错过了某些包裹。
下面是一个更简单的版本来说明:
library(dplyr)
library(ggplot2)
library(igraph)
library(ggraph)
terms <- sample(letters[1:10],50,replace=T)
count <- sample(1:50,25,replace=T)
bigrams <- data_frame(term1=terms[1:25],term2=terms[26:50],occur=count) %>%
arrange(desc(occur)) %>%
graph_from_data_frame()
a <- grid::arrow(type = "closed", length = unit(.15, "inches"))
而且我得到的情节不正确(甚至图例也没有正确显示):
ggraph(bigrams, layout = "fr") +
geom_edge_link(aes(edge_alpha = occur), show.legend = FALSE,
arrow = a, end_cap = circle(.07, 'inches')) +
geom_node_point(color = "lightblue", size = 5) +
geom_node_text(aes(label = name), vjust = 1, hjust = 1) +
theme_void()
ggraph(bigrams, layout = "fr") +
geom_edge_link(aes(edge_alpha = occur, edge_width = occur), edge_colour = "cyan4") +
geom_node_point(size = 5) +
geom_node_text(aes(label = name), repel = TRUE,
point.padding = unit(0.2, "lines")) +
theme_void()
好的,这很有趣,但删除theme_void()
所有解决方案。我想当这本书被写出来时,它会做一些不同的事情。但是第二张图中的图例仍然没有显示,所以仍然有问题: