r - 使用 R 绘制列表

标签 r list plot

我想知道如何绘制列表。

现在我有一个列表

[[1977]] keyword1, keyword2, keyword3, ...
[[1978]] keyword2, keyword5, ...
...
[[2018]] keyword1, keywords3, ...

length(mylist) = 2018
lengts(mylist) = 0,0,0,0,0,......
dput(head(mylist)) = list(NULL, NULL, NULL, NULL, NULL, NULL)

我想使用关键字的频率作为 y 轴和 1977~2018 作为 x 轴来绘制它。

所以它的行数应该等于关键字的数量。有人知道吗?

最佳答案

试试这个例子:

# example data
set.seed(1); myList <- list(sample(LETTERS[1:3], 10, replace = TRUE),
                            sample(LETTERS[1:3], 10, replace = TRUE),
                            sample(LETTERS[1:3], 10, replace = TRUE),
                            sample(LETTERS[1:3], 10, replace = TRUE),
                            sample(LETTERS[1:3], 10, replace = TRUE))
names(myList) <- 1977:1981


library(ggplot2)
library(dplyr)

plotDat <- stack(myList) %>% 
  mutate(myYears = as.numeric(as.character(ind)),
         myWords = values) %>% 
  group_by(myYears, myWords) %>% 
  summarise(myCount = n())

ggplot(plotDat, aes(x = myYears, y = myCount, col = myWords)) +
  geom_line() 

enter image description here

关于r - 使用 R 绘制列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53588964/

相关文章:

python - 删除 matplotlib 中对数图上的特定刻度

用 R 中的向量替换列表

r - 在 R 中使用 readLines(url) 时如何避免 "too many redirects"错误?

r - 在 Shiny App 的页面开头添加类到 <html> 标签

python - 你应该如何读取二维整数数组?

python - 将列表的相邻元素相乘并相加

python - 索引错误 : list indexing error and wrongful tracking of counters

matlab - 在matlab中用不同颜色在同一个图中绘制多个直方图

r - 在 R data.table 中计算时间增量

matlab - 两行上的 X 轴标签