我正在尝试绘制数据,这些数据用于测量中的双字母组的频率。圆棒图的文档。但是,在RStudio上运行代码时,我看不到实际的图。我不确定自己在做什么错
这是我的代码
sona_dfm <- tokens(sona_corp) %>%
tokens_remove("\\p{P}", valuetype ="regex", padding=TRUE)%>%
tokens_remove("\\d+", padding = TRUE)%>%
tokens_ngrams(n=3) %>%
dfm()
#frequency table
freq_table <- textstat_frequency(sona_dfm, n=25) #top25
# Add lines to the initial dataset
freq_table$id=seq(1, nrow(freq_table))
# Get the name and the y position of each label
label_data=freq_table
number_of_bar=nrow(label_data)
angle= 90 - 360 * (label_data$id-0.5) /number_of_bar # I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)
# Make the plot
p = ggplot(freq_table, aes(x=as.factor(id), y=frequency)) +
geom_bar(stat="identity", fill=alpha("green", 0.3)) +
scale_y_continuous(limits=c(0,1500)) +
theme_minimal() +
theme(
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
plot.margin = unit(rep(-1,4), "cm")
) +
coord_polar(start = 0) +
geom_text(data=label_data, aes(x=id, y=frequency+20, label=feature, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE )+
show(p)
这是我拥有的数据 data