使用R绘制列表 [英] Plot a list using R

查看:56
本文介绍了使用R绘制列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何绘制列表.

I would like to know how to plot a list.

现在我有一个列表

[[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轴来绘制它.

And I would like to plot it using keywords' frequencies as the y-axis and 1977~2018 as the x-axis.

因此,它的行应等于关键字的数量.有人知道吗?

So it should have many lines equal to the number of the keywords. Does anyone have any idea?

推荐答案

尝试以下示例:

# 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() 

这篇关于使用R绘制列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆