1

Does anyone know how to change the ylim on Bland-Altman plots when using this code? I would like to use the code below for the bland-altman plots because I like the way they look and how easy it is to add the 95% CIs.

library(BlandAltmanLeh)

set.seed(1)
a <- rnorm(40,30,10)
b <- 1.01*a + rnorm(40)
x <- bland.altman.plot(a,b, xlab="mean", ylab="difference")
rawr
  • 20,481
  • 4
  • 44
  • 78
CatM
  • 284
  • 2
  • 12
  • 2
    not possible considering how they wrote the function. you can recreate the basic plot with `ba <- bland.altman.stats(a, b); plot(ba$means, ba$diffs, ylim = c(-3, 2), panel.last = abline(h = ba$lines, lty = 2))` and change as you want. just read the code for `BlandAltmanLeh:::bland.altman.base` to see how it is drawn – rawr Sep 28 '20 at 01:40
  • doesn't look as pretty though as I had a lot of added stuff, e.g. CI. Super annoying. Must be for a good reason, but when you want to have two Bland-Altman plots side by side, it kind of makes sense for them to have the same y axis. – CatM Sep 28 '20 at 01:53
  • 1
    just read the code for `BlandAltmanLeh:::bland.altman.base` and use the same calls and it will look identical. there are three calls to `abline`, I only showed one – rawr Sep 28 '20 at 02:48

1 Answers1

0

I managed to code a bland-altman plot very similar to the one obtain by that package:

library(BlandAltmanLeh)


Diff <- data.frame(Diff1 = runif(50, 250.0, 500.0), Diff2 = runif(50, 200.0, 400.0)) 

ba.stats <- bland.altman.stats(Diff$Diff2, Diff$Diff1)
summary(ba.stats$CI.lines)


ba.stats2 <- as.data.frame(cbind(ba.stats$means, ba.stats$diffs))

BA.plot <- ggExtra::ggMarginal(ggplot(ba.stats2, aes(V1,V2)) + geom_point() + theme_bw() +
                       geom_hline(yintercept = ba.stats$lines, linetype="dashed", size=1)+
                       labs(x = "Means", y = "Difference (S2-S1)")+  ylim(-300, 150) +
                       geom_hline(yintercept = ba.stats$CI.lines, col = "grey", linetype="dashed", size = 0.70), type = "histogram")

print(BA.plot)

enter image description here

CatM
  • 284
  • 2
  • 12