0

I would like to visualize Vargha & Delaney's A in ggplot for educational purposes.

A is an effect size used to compare ordinal data of two groups that depend on each data point's upward/downward/sideways comparison to all data points of the other group.

For this, I would like to be able to show all upward, downward, and equal comparisons of data points in different colors. For an example of what I'm looking for, check out this rough scribble rough scribble

For reproducibility's sake here is some data to try it with:

library(tidyverse)

data_VD <- tibble(
  A = c(1, 2, 3, 6),
  B = c(1, 3, 7, 9)
)

For reference to how A is calculated, see https://journals.sagepub.com/doi/10.3102/10769986025002101, though it shouldn't be necessary for creating the plot.

mspar
  • 3
  • 2
  • 2
    What is your input data? Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that can be used to test and verify possible solutions. – MrFlick May 24 '22 at 15:02

1 Answers1

1

You could do:

library(tidyverse)

long_dat <- data_VD %>%
  {expand.grid(A = .$A, B = .$B)} %>%
  mutate(change = factor(sign(B - A))) 

ggplot(pivot_longer(data_VD, everything()), aes(x = name, y = value)) +
  geom_segment(data = long_dat, size = 1.5,
            aes(x = 'A', xend = 'B', y = A, yend = B, color = change)) +
  geom_point(size = 4) +
  scale_color_manual(values = c('#ed1e26', '#fff205', '#26b24f')) +
  theme_classic(base_size = 20) +
  scale_y_continuous(breaks = 1:10) +
  labs(x = '', y = '') +
  theme(legend.position = 'none')

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87