Hello,
I would like to create Bland Altman plots as part of my bachelor thesis. For this purpose I have read in a total file with all data. The first column of the Excel table contains the axis designations, the second data of a Vicon system and the third data of a developed sensor system.
So I have 3 columns with 60 rows each.
Axis Vicon M5Stack
x value value
x value value
.
.
.
y value value
.
.
.
z value value
.
.
.
I have created three single Bland Altman plots via "BlandAltmanLeh". Now I would like to merge them with "facet_wrap" to one plot. Unfortunately I don't know if this is possible at all. Should this work I would like to know how to use "facet_wrap" to make this work.
# load libraries
library(readxl)
library(DescTools)
library(BlandAltmanLeh)
library(ggplot2)
# import all data
data_xls_all <- read_excel("Auswertung_Schnell.xlsx", na="NA")
# create variables
M5Stack_x <- signif(data_xls_all$M5Stack[c(1:20)],digits = 4)
Vicon_x <- signif(data_xls_all$Vicon[c(1:20)], digits = 4)
M5Stack_y <- signif(data_xls_all$M5Stack[c(21:40)], digits = 4)
Vicon_y <- signif(data_xls_all$Vicon[c(21:40)], digits = 4)
M5Stack_z <- signif(data_xls_all$M5Stack[c(41:60)], digits = 4)
Vicon_z <- signif(data_xls_all$Vicon[c(41:60)], digits = 4)
# Bland Altman Analysis: X
x <- bland.altman.plot(Vicon_x,M5Stack_x, graph.sys = "ggplot2", two=1.96)
x + xlab("average (m)") + ylab("difference (M5Stack-Vicon) (m)") +
ggtitle("Bland-Altman: x axis: 240bpm") +
theme(plot.title=element_text(hjust = 0.5)) +
geom_hline(yintercept = c(0.0000), color="black", size=1) +
geom_hline(yintercept = c(-0.01242), color="red", size=1) +
geom_hline(yintercept = c(0.01705, -0.04188 ), color="blue", size=1) +
geom_point(size = 3) +
theme( axis.line = element_line(colour="black", size = 1, linetype = "solid")) +
theme(panel.background = element_blank()) +
scale_x_continuous(n.breaks = 10) + scale_y_continuous(n.breaks = 10) +
expand_limits(x = c(0.2, 0.45), y = c(-0.1, 0.04)) +
theme(axis.ticks.length=unit(.25, "cm"),
axis.ticks = element_line(size = 0.5))
# Bland Altman Analysis: Y
y <- bland.altman.plot(Vicon_y,M5Stack_y, graph.sys = "ggplot2", two=1.96)
y + xlab("average (m)") + ylab("difference (M5Stack-Vicon) (m)") +
ggtitle("Bland-Altman: y axis: 240bpm") +
theme(plot.title=element_text(hjust = 0.5)) +
geom_hline(yintercept = c(0.0000), color="black", size=1) +
geom_hline(yintercept = c(-0.02479), color="red", size=1) +
geom_hline(yintercept = c(0.03206, -0.08163 ), color="blue", size=1) +
geom_point(size = 3) +
theme( axis.line = element_line(colour="black", size = 1, linetype = "solid")) +
theme(panel.background = element_blank()) +
scale_x_continuous(n.breaks = 10) + scale_y_continuous(n.breaks = 10) +
expand_limits(x = c(0.2, 0.45), y = c(-0.1, 0.04)) +
theme(axis.ticks.length=unit(.25, "cm"),
axis.ticks = element_line(size = 0.5))
# Bland Altman Analysis: Z
z <- bland.altman.plot(Vicon_z,M5Stack_z, graph.sys = "ggplot2", two=1.96)
z + xlab("average (m)") + ylab("difference (M5Stack-Vicon) (m)") +
ggtitle("Bland-Altman: z axis: 240bpm") +
theme(plot.title=element_text(hjust = 0.5)) +
geom_hline(yintercept = c(0.0000), color="black", size=1) +
geom_hline(yintercept = c(-0.00316), color="red", size=1) +
geom_hline(yintercept = c(0.03998, -0.0463 ), color="blue", size=1) +
geom_point(size = 3) +
theme( axis.line = element_line(colour="black", size = 1, linetype = "solid")) +
theme(panel.background = element_blank()) +
scale_x_continuous(n.breaks = 10) + scale_y_continuous(n.breaks = 10) +
expand_limits(x = c(0.2, 0.45), y = c(-0.1, 0.04)) +
theme(axis.ticks.length=unit(.25, "cm"),
axis.ticks = element_line(size = 0.5))
# Facet_wrap
BA <- ggplot(x,y,z) + facet_wrap(~Axis) ?????
I would be grateful for help!
Jan