我有一张桌子
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。
我想要按日期绘制,我也可以得到日期,但对我来说不是那么重要。但我一直收到错误。字符串不是歧义格式。如下所示:
我似乎不能这样做。
我想绘制随时间变化的频率图(过去2年)。
这是在我制作的一个闪亮的应用程序中,但输出结果要了我的命。
有什么建议吗?
我很感谢你的反馈。
发布于 2017-09-26 20:20:57
试试这个:
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
詹姆斯
发布于 2017-09-26 20:27:20
从table开始
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的组合
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)https://stackoverflow.com/questions/46425995
复制相似问题