Skip to content

Feauture request: Custom ribbon for geom_abline #2381

@benediktclaus

Description

@benediktclaus

Hi,

in psychology there is a simple method for assessing clinical significance. Therefore the pre treatment score of an instrument (e.g. questionnaire) for every patient is plotted against the post treatment score. In the example below, all points that fall below the center diagonal show an improvement. But the instrument used has an error of measurement, indicated by the surrounding diagonals.

The workaround for this is a little annoying so it would be extremely helpful to create a custom ribbon for a geom_abline with manual specifications for ymin and ymax. Thus the area of interest would be shaded and could have a legend entry.

library(ggplot2)

# Some example data, scores on a questionnaire per patient before and after treatment
pre.x <- rnorm(70, mean = 24, sd = 4)
post.x <- rnorm(70, mean = 12, sd = 4)
clinical.data <- data.frame(pre.x, post.x)

# This tells us that changes from pre to post within 3.2 points
# fall into the error of measurement of that questionnaire
error.measurement <- 3.2

# Plot
clinical.significance.plot <- ggplot(clinical.data, aes(x = pre.x, y = post.x)) +
  geom_point() +
  geom_abline(slope = 1, intercept = 0) +
  geom_abline(slope = 1, intercept = -error.measurement) +
  geom_abline(slope = 1, intercept = +error.measurement) +
  coord_cartesian(xlim = c(0,40), ylim = c(0,40))
clinical.significance.plot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions