Question: RShiny interactive volcano plots
0
gravatar for chetana
28 days ago by
chetana30
San Diego
chetana30 wrote:

Hi everyone,

I'm a newbie to Rshiny and I'm trying to make a Rshiny app using this link mentioned here (https://bioinformatics-core-shared-training.github.io/shiny-bioinformatics/interactive-plots), it uses ggplot+plotly to make the plot interactive. I want to try it on my timepoint data and have different timepoints as options for selectinput(). But the problem is that for each timepoint there would be different X (Foldchange ) and Y (-log10Pvalue) axes. I'm not sure how to implement this on my data using the example in the above mentioned link. Any suggestion regarding this approach will be really appreciated. Thanks in advance for your help.

ADD COMMENTlink modified 5 days ago by h.mon9.6k • written 28 days ago by chetana30

What does this have to do with bioinformatics, please?

ADD REPLYlink written 28 days ago by Michael Dondrup43k
2

I'm happy to explain, Michael. Bioinformatics is an interdisciplinary field and according to me if we're trying to solve a biological problem with a programmatic approach I consider it to be a bioinformatics problem. Since I'm working with biological data/ expression data I think it is relevant to call it a bioinformatics issue. Please let me know if you have any other concerns. Thanks!

ADD REPLYlink modified 5 days ago • written 5 days ago by chetana30

Sorry, this was not evident from the original post.

ADD REPLYlink written 5 days ago by Michael Dondrup43k

I fixed the URL in your post here

As for your problem, its hard to know for sure without seeing an example of your data, but I would suggest adding an extra column in your dataframe for a time-point factor level (e.g. timepoint) for each entry, and then include faceting as described here;

ggplot(differentialExpressionResults, aes(x = logFC, y = minusLog10Pvalue, colour = probe.type)) +
      geom_point() +
      xlab("log fold change") +
      ylab("-log10(P-value)") +
      theme(legend.position = "bottom") + 
      facet_grid(. ~ timepoint)

This should give you multiple plots side-by-side, one for each factor level.

Alternatively, you could adjust the color, fill, or group to use the new timepoint factor level, though this would be more confusing to look at since all points for all timepoint's would be displayed in the same plot.

ADD REPLYlink modified 5 days ago • written 5 days ago by steve1.2k

Thanks for your reply Steve and sorry if I was not clear asking the question. Here I include the headers of the dataframe as an example as the data is really huge.

probe gene_symbol Timepoint0_FC Timepoint0_P Timepoint3_FC Timepoint3_P Timepoint7_F Timepoint7_P

Here FC is the foldchange and P is the adj. p. value for each timepoint mentioned there ie 0, 3, 7,.., 24. I'm actually working with the second part of the code mentioned in the link and named as Plotly, where the author uses plotly and ggplot to make the interactive volcano plot (https://bioinformatics-core-shared-training.github.io/shiny-bioinformatics/interactive-plots). I kind of got the script to work with just one timepoint.

I don't intend to show all the timepoint data at once but want to implement in the control widgets as a select box feature shown in this link (https://shiny.rstudio.com/tutorial/written-tutorial/lesson3/) implemented using selectinput() where we can list out the options that the user wishes to chose. For example if the user selects timepoint_3 the plot should display FC vs P of timepoint 3 which is extracted from the dataframe above. This is my thought behind it, but I'm not sure how to implement it. Thanks for looking into it.

ADD REPLYlink modified 5 days ago • written 5 days ago by chetana30
`ui <- fluidPage(
 titlePanel("Volcano Plotly"),
 fluidRow(
   column(
     width = 10,
       plotlyOutput("volcanoPlot", height = "500px")
    ),
      column(
         width = 8,
           dataTableOutput("selectedProbesTable")
         )
     )
)
server <- function(input, output) {
 differentialExpressionResults <-
read.table("Annotated_Time24_ICL004.txt", stringsAsFactors = FALSE, header = TRUE) %>%
mutate(
  minusLog10Pvalue = -log10(P),
  tooltip = ifelseis.na(gene_symbol), probe, paste(gene_symbol, " (", probe, ")", sep = ""))
) %>%
sample_n(16667)      
output$volcanoPlot <- renderPlotly({

plot <- differentialExpressionResults %>%
  ggplot(aes(x = logFC,
             y = minusLog10Pvalue,
             colour = Pattern_number,
             text = tooltip,
             key = row.names(differentialExpressionResults))) +
  geom_point() +
  xlab("log fold change") +
  ylab("-log10(P-value)")

plot %>%
  ggplotly(tooltip = "tooltip") %>%
  layout(dragmode = "select")
})

output$selectedProbesTable <- renderDataTable({

  eventData <- event_data("plotly_selected")

  selectedData <- differentialExpressionResults %>% slice(0)
if (!is.null(eventData)) selectedData <- differentialExpressionResults[eventData$key,]

selectedData %>%
  transmute(
    probe,
    gene = gene_symbol,
    Pattern_number,
    `log fold change` = signif(logFC, digits = 2),
    `p-value` = signif(P, digits = 2)
    )
 },
  options = list(dom = "tip", pageLength = 10, searching = FALSE)
  )
}

 shinyApp(ui, server, options = list(height = 600))`

Here is the code that I used for just one timepoint.

ADD REPLYlink modified 5 days ago • written 5 days ago by chetana30
1

Assuming the rest of the app works you can use the selectInput() to change the data. It looks like the DE test is loaded at the read.table call? If that's true you can do:

ui <- ...
    selectInput(inputId= 'DEtest', label='Pick a timepoint!', choices = c("3","7","24"...etc))
...

server <- ...
    file = reactive({
        paste0("Annotated_Time", input$DEtest,"_ICL004.txt")
    })

    output$volcanoPlot <- renderPlotly({
    ##I moved these:
        read.table(file(), stringsAsFactors = FALSE, header = TRUE) %>%
mutate(
      minusLog10Pvalue = -log10(P),
      tooltip = ifelseis.na(gene_symbol), probe, paste(gene_symbol, " (", probe, ")", sep = ""))
    ) %>%
    sample_n(16667)

Note I moved the read.table() and ensuing functions into the renderPloty so they are reactive. Otherwise you have to wrap them in reactive({})

ADD REPLYlink modified 5 days ago • written 5 days ago by Jacob Warner550

Please use ADD COMMENT/ADD REPLY when responding to existing posts to keep threads logically organized.

You can always add new information to your original/existing posts by editing. Submit Answers should only be used for answers for the original question.

ADD REPLYlink modified 5 days ago • written 5 days ago by genomax39k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1028 users visited in the last hour