This is a test version of Biostars. For the public version, visit https://www.biostars.org.
geom_point, indicate data points outside plot

On this plot, data points that are outside the limits of the plot are pointed to using triangles:

https://i.imgur.com/ScTCGMw.png from http://www.bioconductor.org/help/workflows/rnaseqGene/#ma-plot

Is it possible to do something similar using ggplot2 (geom_point)?

Thank you.

geom_point

1 answer

I'm guessing your example data looks something like:

xs <- data.frame(aveCPM = 1:6, logFC = c(0.5, 10, -0.2, 0.1, -0.4, -2))

Then you can basically do this (you'll presumably want to drop the legend and fix the colours):

library(ggplot2)
library(dplyr)

xs %>%
    dplyr::mutate(
        out_of_bounds = abs(logFC) > 3,
        logFC = ifelse(out_of_bounds, 3 * sign(logFC), logFC)
        ) %>%
    ggplot(aes(x = aveCPM, y = logFC, shape = out_of_bounds)) +
    geom_point() +
    ylim(-3, 3)

Log in to answer this question.