Bland and altman plot differences as percentage

Chloe Source

The code below is for a bland altman plot, with on the y-as the differences of 'datax' and 'datay' and on the x-as the mean of 'datax' and 'datay'. But I want to plot on the y-as the differences as percentage, like this: (datax-datay)/mean*100 with all the lines of lower limits and upper limits. Can someone help me with the code?

 b1.stat <- bland.altman.stats(datax, datay)


 b1.stat.data <- data.frame(means=b1.stat$means, diffs=b1.stat$diffs)



 ggplot(data=b1.stat.data, aes(x=means, y=diffs)) + 
  geom_point() +
  geom_hline(yintercept=b1.stat$CI.lines[["lower.limit.ci.lower"]]) +
  geom_hline(yintercept=b1.stat$CI.lines[["lower.limit.ci.upper"]]) +
  geom_hline(yintercept=b1.stat$CI.lines[["upper.limit.ci.lower"]]) +
  geom_hline(yintercept=b1.stat$CI.lines[["upper.limit.ci.upper"]]) +
  geom_hline(yintercept=b1.stat$CI.lines[["mean.diff.ci.lower"]], colour= 
 'red', linetype = "dashed") +
  geom_hline(yintercept=b1.stat$CI.lines[["mean.diff.ci.upper"]], colour= 
 'red', linetype = "dashed") + 
  geom_hline(yintercept=b1.stat$lines[["lower.limit"]], linetype=2) + 
  geom_hline(yintercept=b1.stat$lines[["upper.limit"]], linetype=2) + 
  geom_hline(yintercept=b1.stat$lines[["mean.diffs"]], colour= 'red') + 
  geom_hline(yintercept=0) 
rplotdifference

Answers

answered 3 months ago Vishesh Shrivastav #1

Create your own vector of percentage values

b1.stat <- bland.altman.stats(datax, datay)
# Difference vector
differences <- datax - datay
# Differences as percentages
diff.as.perentages <- (differences / b1.stat$means) * 100

b1.stat.data <- data.frame(means = b1.stat$means, diffs = diff.as.perentages)

comments powered by Disqus