forked from jsobel1/Interactive_timeline_wiki_COVID-19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive_timeline.R
134 lines (111 loc) · 5.42 KB
/
interactive_timeline.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
library("ggrepel")
library(shiny)
library(ggplot2)
library(ggthemes)
library(plotly)
library(dplyr)
library(lubridate)
dfcr=read.csv("dfcr_annot3_doi_filtered.csv",sep=";")
dfcr$tsc=dmy(gsub("/","-",dfcr$tsc))
dfcr$wiki=paste("http://en.wikipedia.org/?curid=",dfcr$pageid,sep="")
dfcr$label=paste('<a href="',dfcr$wiki,'">',dfcr$art,'</a>',sep="")
#pdf("timeline_HMC_not_colored_types_2.pdf",height=10,width=20)
# ggplot(dfcr,aes(x=tsc,y=0,fill=type))+
# geom_point(aes(colour=type))+
# geom_label_repel(aes(label =art),nudge_y= 0.5, #fill = factor(type)
# direction = "y",
# angle = 0,
# vjust = 0,segment.alpha =0.2,
# size=3,segment.size = .5)+
# scale_x_date()+theme_minimal()+
# ylim(0,0.5)+scale_colour_brewer("type", palette="Dark2")+
# scale_fill_brewer("type", palette="Dark2")+
# theme(legend.position = "bottom")+facet_wrap(~type,ncol=1)
#dev.off()
#write.table(dfcr,"wiki_articles_nodes_info.csv",quote=F,row.names=F,sep=";")
#############
library(shiny)
library(timevis)
color_pal=c("#fbb4ae",
"#b3cde3",
"#ccebc5",
"#decbe4",
"#fed9a6",
"#ffffcc")
data <- data.frame(
id = 1:dim(dfcr)[1],
content = dfcr$label,#dfcr$art,
start = dfcr$tsc,
end =rep(NA,dim(dfcr)[1]),
group = as.numeric(dfcr$type),
style = paste("background-color: ",color_pal[as.numeric(dfcr$type)],";")) #,
# groups = data.frame(id = 1:6, content = levels(unique(dfcr$type)))
#timevis(data, groups = data.frame(id = 1:6, content = levels(unique(dfcr$type))),zoomFactor=0.1)%>%setWindow("2001-01-01", Sys.Date()) %>%
# setGroups(data.frame(id = 1:6, content = levels(unique(dfcr$type))))
ui <- fluidPage(
timevisOutput("timeline")
)
server <- function(input, output, session) {
output$timeline <- renderTimevis({
timevis(data,groups = data.frame(id = 1:6, content = levels(unique(dfcr$type))),zoomFactor=0.1)%>%setWindow("2004-04-01","2006-01-01")%>%
setGroups(data.frame(id = 1:6, content = levels(unique(dfcr$type))))
})
}
shinyApp(ui = ui, server = server)
# ui <- fluidPage(
# titlePanel("Interactive circadian field timeline"),
# # sidebarLayout(
# # sidebarPanel(
# # checkboxGroupInput("variable", "type of atricles to show:",
# # c("Concept" = "Concept",
# # "Molecule/gene" = "Molecule/gene",
# # "Disease"="Disease",
# # "Model/tissue" = "Model/tissue",
# # "People" = "People",
# # "Other" = "Other"
# # )),
# # sliderInput("DatesMerge",
# # "Dates:",
# # min = as.Date("2001-01-01","%Y-%m-%d"),
# # max = as.Date("2019-12-01","%Y-%m-%d"),
# # value=c(as.Date("2010-12-01"),as.Date("2018-12-01")),
# # timeFormat="%Y-%m-%d",dragRange = TRUE),
# # sliderInput("yrange",
# # "Y Range:",
# # min = 0,
# # max = max(dfcr$length),
# # value=c(0,max(dfcr$length)),
# # dragRange = TRUE)
# # ),
# mainPanel(
# plotlyOutput("plot2")))
#
# server <- function(input, output) {
#
# output$plot2 <- renderPlotly({
# print(
# ggplotly(
# #ggplot(dplyr::filter(dfcr,type %in% input$variable ),aes(x=tsc,y=length,fill=type,label=art))+
# ggplot(dfcr,aes(x=tsc,y=length,fill=type,label=label))+
# geom_point(aes(colour=type),alpha=0.3)+geom_text(aes(colour=type),size=2,vjust = 0, nudge_y = 2)+
# #geom_text_repel(aes(label =art),nudge_y= 0.5, #fill = factor(type)
# # direction = "y",
# # angle = 0,
# # vjust = 0,segment.alpha =0.2,
# # size=3,segment.size = .5)+
# scale_x_date()+theme_minimal()+#xlim(input$DatesMerge)+
# #ylim(input$yrange)+
# scale_colour_brewer("type", palette="Dark2")+
# scale_fill_brewer("type", palette="Dark2")+
# theme(legend.position = "bottom")+ labs(x ="time",y="Article size"))%>%layout(autosize = F, width = 1200, height = 500,hovermode="closest"))#
# #p$data[[1]]$links = links
# #p
# #p <- plot_ly()
# #p <- add_trace(p, uid=trace1$uid, line=trace1$line, mode=trace1$mode, name=trace1$name, type=trace1$type, x=trace1$x, y=trace1$y, marker=trace1$marker, error_x=trace1$error_x, error_y=trace1$error_y, text=trace1$text, textfont=trace1$textfont)
# #p <- layout(p, font=layout$font, smith=layout$smith, title=layout$title, width=layout$width, xaxis=layout$xaxis, yaxis=layout$yaxis, bargap=layout$bargap, boxgap=layout$boxgap, height=layout$height, legend=layout$legend, margin=layout$margin, barmode=layout$barmode, boxmode=layout$boxmode, autosize=layout$autosize, dragmode=layout$dragmode, hovermode=layout$hovermode, titlefont=layout$titlefont, separators=layout$separators, showlegend=layout$showlegend, bargroupgap=layout$bargroupgap, boxgroupgap=layout$boxgroupgap, hidesources=layout$hidesources, plot_bgcolor=layout$plot_bgcolor, paper_bgcolor=layout$paper_bgcolor)#facet_wrap(~type,ncol=1)+ theme_gdocs()
#
# })
# }
#
# shinyApp(ui, server)
#############