Include trend line in GSEA plot

This commit is contained in:
Elias Projahn 2022-07-02 23:37:13 +02:00
parent cc17c13888
commit aed13425ed
2 changed files with 10 additions and 4 deletions

Binary file not shown.

View file

@ -25,20 +25,26 @@ result <- if (file.exists(file_path)) {
result result
} }
result[, result := lapply(analysis, function (a) a$result)] result[, result := lapply(analysis, function(a) a$result)]
result <- result[, rbindlist(result), by = bucket] result <- result[, rbindlist(result), by = bucket]
data <- result[, .(count = .N), by = c("bucket", "source")] data <- result[, .(count = .N), by = c("bucket", "source")]
data[, total := sum(count), by = bucket]
smooth_model <- loess(total ~ bucket, data, span = 0.25)
fig <- plotly::plot_ly() |> fig <- plotly::plot_ly(data) |>
plotly::add_bars( plotly::add_bars(
data = data,
x = ~bucket, x = ~bucket,
y = ~count, y = ~count,
color = ~source color = ~source
) |> ) |>
plotly::add_lines(
x = ~bucket,
y = predict(smooth_model),
name = "All (smoothed)"
) |>
plotly::layout( plotly::layout(
xaxis = list(title = "Bucket of genes (n = 500)"), xaxis = list(title = glue::glue("Bucket of genes (n = {bucket_size})")),
yaxis = list(title = "Number of associated terms"), yaxis = list(title = "Number of associated terms"),
barmode = "stack", barmode = "stack",
legend = list(title = list(text = "<b>Source of term</b>")) legend = list(title = list(text = "<b>Source of term</b>"))