Browse code

adding changes to new plots

pablo-rodr-bio2 authored on 17/06/2020 10:14:40
Showing3 changed files

... ...
@@ -207,11 +207,16 @@ gsva_information <- function(input, output, session, newY, genes) {
207 207
   # Rendering graph1
208 208
   dat.t <- melt(as.data.table(generated_gsva, keep.rownames = "gene.sets"), 
209 209
                 variable.name = "Sample", id.vars="gene.sets")
210
+  n <- length(levels(dat.t$Sample))
211
+  dd.col <- hcl(h = seq(15, 375, length=n), l = 65, c = 100)[1:n]
212
+  names(dd.col)  <- levels(dat.t$Sample)
213
+  
210 214
   
211 215
   output$plot <- renderPlotly({
212 216
     p <- ggplot(data = dat.t, aes(x=value, color=Sample)) +
213 217
       stat_density(geom="line", position = "identity") +
214
-      theme(legend.position = "none") + labs(x="GSVA Scores", y="Density")
218
+      theme(legend.position = "none") + labs(x="GSVA Scores", y="Density") +
219
+      scale_color_manual("Legend", values = dd.col)
215 220
     ggplotly(p, tooltip = "Sample", source = "click1")
216 221
   })
217 222
   
... ...
@@ -224,6 +229,12 @@ gsva_information <- function(input, output, session, newY, genes) {
224 229
   
225 230
   #Rendering text2
226 231
   output$text2 <- renderUI({
232
+    title1 <- sample.c()
233
+    h2(tags$b(title1), align ="center")
234
+  })
235
+  
236
+  #Rendering text3
237
+  output$text3 <- renderUI({
227 238
     HTML(paste("<br/>", "\t To see the Kernel Density Estimation of genes of 
228 239
     any given Gene Set in this Sample,  click on any point in this plot and a
229 240
     second plot will appear bellow it", "<br/>", sep="<br/>"))
... ...
@@ -245,10 +256,9 @@ gsva_information <- function(input, output, session, newY, genes) {
245 256
     data <- dat.t[Sample==sample.c()]
246 257
     p <- ggplot(data = data, aes(x=value, color=Sample)) +
247 258
       stat_ecdf(geom="point") + theme(legend.position = "none") + 
248
-      labs(x=paste0("GSVA Scores of ", sample.c()), y="Empirical Cumulative Density") +
249
-      scale_color_discrete(drop=TRUE, limits=levels(dat.t$Sample))
250
-    p <- ggplotly(p, source="click2")
251
-    style(p, text=data$gene.sets)
259
+      labs(x="GSVA Scores in selected sample", y="Empirical Cumulative Density") +
260
+      scale_color_manual("Legend", values = dd.col)
261
+    p <- ggplotly(p, source="click2") %>% style(text=data$gene.sets)
252 262
   })
253 263
   
254 264
   output$plot2 <- renderPlotly({
... ...
@@ -273,12 +283,16 @@ gsva_information <- function(input, output, session, newY, genes) {
273 283
     df <- as.data.frame(x)
274 284
     df$x <- as.numeric(df$x)
275 285
     df$Gene <- rownames(df)
276
-    p1 <- ggplot(data = df, aes(x=x)) +
286
+    df$Sample <- sample.c()
287
+    p1 <- ggplot(data = df, aes(x=x, color = Sample, label = Gene)) +
277 288
       stat_density(geom="line", position = "identity") +
278
-      geom_rug(aes(color=Gene)) +
279
-      theme(legend.position = "none") + 
280
-      labs(x=paste0("Gene Expressions from GeneSet ", gene.set()), y="Density") 
281
-    ggplotly(p1) %>% style(hoverinfo="none", traces = 1)
289
+      geom_rug() + theme(legend.position = "none") + 
290
+      labs(x="Gene Expressions in selected sample", y="Density") +
291
+      xlim(as.numeric(range(newY))) +
292
+      scale_color_manual("legend", values= dd.col)
293
+    ggplotly(p1, tooltip = c("Gene", "x")) %>% style(hoverinfo="none", traces = 1) %>%
294
+      layout(title = list(text = paste0('<br><sup><i>', gene.set(), '</i></sup>'),
295
+                          font = list(size=15)))
282 296
   })
283 297
   
284 298
   # Rendering Session Info
... ...
@@ -77,7 +77,8 @@ mainDataInput <- function(id) {
77 77
                                  tableOutput("result"),
78 78
                                  uiOutput("download")),
79 79
                         tabPanel("Gene Sets",
80
-                                 htmlOutput("text2"),
80
+                                 uiOutput("text2"),
81
+                                 htmlOutput("text3"),
81 82
                                  plotlyOutput("plot2"),
82 83
                                  plotlyOutput("plot3")),
83 84
                         tabPanel("Session Info",
... ...
@@ -2,4 +2,4 @@
2 2
 	font-size: 16px;
3 3
 	font-weight: bold;
4 4
 	color: green;
5
-      }
5
+      }
6 6
\ No newline at end of file