2017-08-03 17 views
0

私は40802遺伝子名のデータフレームのリストを持っており、14000の記事情報を持つデータフレームを持っています。記事情報には、記事、要約、曜日、月、年が含まれます。テキスト内の単語の頻度をカウントしてプロットを作成

日付を通常の形式に、抽象を文字に変換しました。

私は時間のXのプロットを持っていますが、遺伝子名の頻度は要約に表示されます。 EG

| Date  | Gene Name | Frequency | 
|------------|-----------|-----------| 
| 2017-03-20 | GAPDH  | 5   | 
| 2017-03-21 | AKT  | 6   | 

は基本的に、私が最も頻繁に最後の100日に発表された遺伝子名を知っていると言っgenenamesの進化を見るためにタイムラインを持っていると思います。傾向のようなもの。

library(RISmed) 

##Research the query - can be anything relevant to protein expression. 
##Multiple research not tested yet 

search_topic <- 'protein expression' 

##Evaluate the query with reldate = days before today, retmax = maximun number of returned results 

search_query <- EUtilsSummary(search_topic, retmax=15000, reldate = 100) 
##explore the outcome 

summary(search_query) 

##get the ids for tall the queries to get the articles 

QueryId(search_query) 
##get all the records associated with the ID - THIS TAKES LOOONG TIME 

records<- EUtilsGet(search_query) 

##Analyze the structure 
str(records) 

summary(records) 

##Create a data frame with article/abstract/date 

pubmed_data <- data.frame('Title'=ArticleTitle(records),'Abstract'=AbstractText(records), 
          "Day"=DayPubmed(records), "Month" = MonthPubmed(records), "Year"=YearPubmed(records)) 
##explore the data 
head(pubmed_data,1) 
##gene names 
genename <- read.csv("genename.csv", header = T, stringsAsFactors = F) 

##remove any NA tittles 

pubmed <-pubmed_data[-which(is.na(pubmed_data$Title)), ] 
##Coerce the date to YYYY-MM-DD 

pubmed$Date <- as.Date(paste(pubmed$Day , pubmed$Month , sep = ".") , format = "%d.%m") 

私はたくさん読んだし、genemane [1,1]内のpubmed$Abstract、 を見つけると時間で、それは登場回数をカウントする方法を見つけ出すことはできません。 Xを最後の100日とし、ラインプロテクトをジェネレーション名の頻度とするプロットを作成します。 そして凡例がジェネルネームになります。だからトレンドを見ることができます。

これをどのように行うことができるのか、本当に感謝しています。

私はtmを試してみましたが、さまざまなことを試みましたが、まだ壁に当たっています。私の考えは間違っていますか?

答えて

0
# from: https://stackoverflow.com/questions/45485701/count-frequency-of-words-in-text-and-create-plot 
# get some text 
txt <- c("I have a list of data frame with 40802 gene names and I have data frame with 14000 article information. 
The article information contains Article, Abstract, Day, Month, Year.I have transformed the date into normal format, 
and the abstract as character. I want to have a plot of X in time, and the frequency of the gene names appears in the abstract. 
Basically, I want to know the gene names most frequently published in the last 100 days and have a timeline to see the evolution of said genenames. 
Something like a trend.") 

# cut to ngramms for dataframe example 
txt <- strwrap(x = txt,width = 20) 
# create some data frame 
pubmed_data <- data.frame(Title=abbreviate(names.arg = txt,minlength = 5,method = "left.kept",named = F),Abstract=txt,stringsAsFactors = F) 
pubmed_data 

# tm package 
library(tm) 
wrds <- termFreq(doc = pubmed_data$Abstract,control = list(tolower=TRUE,removePunctuation=TRUE,removeNumbers=TRUE)) 
wrds <- sort(unclass(wrds),decreasing = T) 
wrds <- data.frame(tokens=names(wrds),n=as.integer(wrds)) 
wrds$tokens <- reorder(wrds$tokens,wrds$n) 

library(ggplot2) 
ggplot(data = wrds,aes(x = tokens,y = n,fill=n))+geom_bar(stat="identity")+scale_y_continuous(breaks = 1:max(wrds$n))+ 
    coord_flip() 


# tidy packages 
library(tidytext) 
library(dplyr) 
wrds2 <- pubmed_data %>% select(-Title) %>% unnest_tokens(input = "Abstract",output = "tokens",to_lower = T) %>% 
    filter(grepl(pattern="\\D+",x=.$tokens)) %>% group_by(tokens) %>% 
    count %>% ungroup %>% mutate(tokens=reorder(tokens,n)) 

ggplot(data = wrds2,aes(x = tokens,y = n,fill=n))+geom_bar(stat="identity")+scale_y_continuous(breaks = 1:max(wrds$n))+ 
    coord_flip() 
関連する問題