r - 将自定义线添加到 ggplot 会引发错误:美学长度必须为 1
问题描述
试图在 ggplot 中为一行的一部分着色。这种颜色代表从原始绘图数据中过滤出来的词频排名中有意义的词。
错误:
错误
check_aesthetics()
:美学必须是长度 1 或与数据 (1306062) 相同:x 和 y
原图:
#plot
word_freq_rank <- ggplot(word_list, aes(x = seq_along(freqs), y = freqs, group = 1)) +
geom_line() +
coord_trans(y ='log10', x='log10') +
labs(title = "Rank Frequency Plot", x = "log-Rank", y = "log-Frequency")
文本处理:
# REMOVE STOPWORDS AND INFREQUENT WORDS- TO DEFINE BEST RANGE FOR ANALYSIS, by removing insignificant word indexes
stopword_idx <- which(word_list$words %in% stop_words)
low_frequent_idx <- which(word_list$freqs < 10)
insignificant_idx <- union(stopword_idx, low_frequent_idx)
meaningful_range_idx <- setdiff(1:nrow(word_list), insignificant_idx)
添加行:
# plot the meaningful range of the rank-frequency to use
word_freq_rank + geom_path(mapping = aes(x = meaningful_range_idx, y = freqs[meaningful_range_idx], color="green"), inherit.aes = TRUE)
当我尝试在下面的代码末尾添加该行时会发生错误。我缺少一些基本的东西,但不知所措。任何帮助表示赞赏。
解决方案
推荐阅读
- c++ - Asigning variables for individual elements in a row
- regex - extract string from binary file - regex issue
- openlayers - Continue zooming in when smaller clusters are tapped
- qt - QtQuick 获取基本表单尺寸
- python - 包含(嵌入式)列表理解的字典理解
- xslt - 改变价值
- php - 使用合并运算符和函数调用的最简单方法
- angular - 我什么时候可以检查是否给出了“@Input()”?
- javascript - 内容不显示
- python - np.where() 解决方案说明