首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何按日期绘制Frequency?表的问题

如何按日期绘制Frequency?表的问题
EN

Stack Overflow用户
提问于 2017-09-26 20:02:41
回答 2查看 439关注 0票数 1

我有一张桌子

代码语言:javascript
复制
    library(RISmed)
search_topic <- "BID"
search_query <- EUtilsSummary(search_topic, mindate = 2016, maxdate=2018)
summary(search_query)
QueryId(search_query)
records <- EUtilsGet(search_query)
y <- data.frame(cbind("year"= YearPubmed(records), "month"= MonthPubmed(records)))
date()
count<-table(y)
count

month
year    1  2  3  4  5  6  7  8  9 10 11 12
  2016 49 54 49 59 45 54 43 44 40 47 42 42
  2017 52 35 52 48 30 37 43 42 25  0  0  0

我创建了一个带计数的数据帧,但一旦我尝试将其转换为as.Date,它就会转换为NA。

我想要按日期绘制,我也可以得到日期,但对我来说不是那么重要。但我一直收到错误。字符串不是歧义格式。如下所示:

Graph of Input(BID)

我似乎不能这样做。

我想绘制随时间变化的频率图(过去2年)。

这是在我制作的一个闪亮的应用程序中,但输出结果要了我的命。

有什么建议吗?

我很感谢你的反馈。

EN

回答 2

Stack Overflow用户

发布于 2017-09-26 20:20:57

试试这个:

代码语言:javascript
复制
library(RISmed)
library(dplyr)
library(ggplot2)
search_topic <- "BID"
search_query <- EUtilsSummary(search_topic, mindate = 2016, maxdate=2018)
summary(search_query)
QueryId(search_query)
records <- EUtilsGet(search_query)
y <- data.frame(cbind("year"= YearPubmed(records), "month"= MonthPubmed(records)))
date()
count<-table(y)
count

y$date <- as.Date(strptime(paste(y$year, y$month, "01", sep="-"), "%Y-%m-%d", tz = "UTC"), origin="1970-01-01")

y %>% group_by(date) %>% summarise(n.citation = length(date)) %>%
  ggplot(aes(x=date, y = n.citation)) + geom_point()][1]][1]

HTH

詹姆斯

票数 2
EN

Stack Overflow用户

发布于 2017-09-26 20:27:20

table开始

代码语言:javascript
复制
tbl <- structure(c(49L, 52L, 54L, 35L, 49L, 52L, 59L, 48L, 45L, 30L, 
54L, 37L, 43L, 43L, 44L, 42L, 40L, 25L, 47L, 0L, 42L, 0L, 42L, 
0L), .Dim = c(2L, 12L), .Dimnames = structure(list(Year = c("2016", 
"2017"), variable = c("1", "2", "3", "4", "5", "6", "7", "8", 
"9", "10", "11", "12")), .Names = c("Year", "variable")), class = c("xtabs", 
"table"), call = xtabs(formula = value ~ Year + variable, data = melted))

您可以将Year-Months的组合

代码语言:javascript
复制
Combs <- expand.grid(attributes(tbl)$dimnames$Year, attributes(tbl)$dimnames$variable)

# or you can use
# Combs <- expand.grid(c("2016","2017"), 1:12))

library(lubridate)
preDates <- apply(Combs, 1, function(x) paste0(x, collapse="-"))
sortedDates <- sort(parse_date_time(preDates, "y-m"))

newdf <- data.frame(Date = sortedDates, Value = c(tbl))
plot(Value ~ Date, data=newdf)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46425995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档