Home > Software design >  plot data points with distance equal to error
plot data points with distance equal to error

Time:03-09

I am quite new to R and am trying to replicate an x axis of quality where the data points are scaled with the distance between them. Eg, Qscore of 5 = error rate 32%, Qscore of 7 = error rate 20% etc as below

Qscore  Error rate
5   32%
7   20%
10  10%
12  6.30%
15  3.20%

I want to plot so that the distance is not equal between the data points, but as the difference between Qscores spatially - ie. the distance between Qscore5 and Qscore7 is far greater than the difference between Q12 and Q15 and I want the graph to represent this spatially.

Is it possible to represent this on the x axis so that if I label the x axis Q5-Q15 the space between Q5 and Q7 labels is larger than the space between the Q12 & Q15 labels etc?

Any pointers to resources would be great - I am using tidyverse and rstatix! Thanks.

CodePudding user response:

If I understand correctly, you have data like this?

data <- tibble(qscore = c(5, 7, 10, 12, 15),
           error_rate = c(0.32, 0.2, 0.1, 0.063, 0.032))

To show the distance in error rate for the qscore, you could do something like this:

data %>% 
  ggplot(aes(x = error_rate))  
  geom_label(aes(label = qscore), y = 0.5)

That would give you a plot like that: enter image description here

Not sure this is what you are looking for but maybe it helps :-)

CodePudding user response:

I think OP is asking for something more where the distance between the points on the x axis is proportional to the error, so more like

library(tidyverse)
library(magrittr)

data <- tibble(qscore = c(5, 7, 10, 12, 15),
               error_rate = c(0.32, 0.2, 0.1, 0.063, 0.032))

data %<>% mutate(
  cumul_dist = cumsum(error_rate))

# Closer to what OP is asking
data %>% 
  ggplot(aes(x = cumul_dist, y=qscore))  
  geom_point()

which gives

this result

However (and I emphasise I'm unaware of the purposes OP needs this graph for), I think a better way to represent would be using error bars like this:

# Better representation of data IMO
data %>% 
  ggplot(aes(x = seq(length(qscore)), y=qscore))  
  geom_point()  
  geom_errorbar(aes(ymin=(qscore-0.5*error_rate), ymax=(qscore 0.5*error_rate)), width=.1)

which gives

this result.

Hope that's useful!

  • Related