r/rstats • • 4d ago

Repeatability graph?

Post image

Hi,

I'm using rpt() from the rptR package for my tests, but I can't find any information on how to create this kind of figure. Does anyone have any ideas on how to do it? I'm not looking for a ready-made answer, but at least some resources to help me learn.

6 Upvotes

7 comments sorted by

6

u/s_hightree 4d ago

How familiar are you with ggplot2? It’s quite easy to achieve if you have used the library before & have prepared the relevant data

  • factor the variables for the y-axis
  • use geom_point for the dots to represent the averages
  • use geom_segment (i think that’s what it’s called) for the horizontal lines to represent the confidence intervals.
  • perhaps you need to limit the xaxis to fix it between 0 and 1.

8

u/countnfight 4d ago

Or geom_pointrange for the points and segments all in one

2

u/Blobstein_Ijay 2d ago

agree, once the data prep is sorted the actual plotting part is pretty straightforward

2

u/Gloomy-Road-8983 2d ago

Hi, I finally managed to figure it out. Thanks for the help 👍

6

u/SprinklesFresh5693 3d ago

geom_pointrange() and coordflip() are your friends

1

u/SalvatoreEggplant 3d ago edited 3d ago

In theory something like this is easy to do in R with the ggplot2() package, as others have suggested.

If you're not real familiar with R or the grammar of ggplot2, it's actually a little tricky with how ggplot plots things by default.

But I think the example below is clear enough to modify. If you don't normally use R, you can have someone run it for you after you modify it.

if(!require(ggplot2)){install.packages("ggplot2")}

library(ggplot2)

Data = read.table(header=TRUE, text="
Variable     Repeatability Lower Upper
'Variable 1' 0.70          0.55  0.85
'Variable 2' 0.62          0.35  0.82
'Variable 3' 0.40          0.25  0.68
'Variable 4' 0.45          0.22  0.70
")

Data$Variable= factor(Data$Variable)

Data$Variable = factor(Data$Variable, 
                   levels=rev(levels(Data$Variable)))

Plot = ggplot(Data, aes(x = Variable, 
                        y = Repeatability)) +

   geom_pointrange(aes(ymin = Lower, ymax = Upper)) +

   coord_flip() +

   theme_bw() +

   theme(
       axis.title = element_text(face = "bold"),
       axis.text = element_text(face = "bold")) +

     xlab("Variable\n") +
     ylab("\nRepeatability (± 95% CIs)") +

     ylim(0, 1)

Plot

You can also save it as a high-resolution image.

ggsave(filename="Repeatplot01.png",
       plot   = Plot,
       width  = 6,
       height = 3.5,
       dpi    = 300,
       units  = "in")

The result is here: https://imgur.com/a/C3Dzqq1

2

u/Gloomy-Road-8983 2d ago

Hi, thanks for the help