This post
describes how to build an interval plot with R, using
ggplot2
or plotrix
. An interval plot is used
to compare groups similar to a box plot or a dot plot. It is used when
the data is continuous. Instead of plotting the individual data point,
an interval plot shows the confidence interval for the mean of the
data.
Firstly, we create an exemple data.
ggplot2
packageHere, we will be using the geom_point()
function to plot
the points on the ggplot and then will be using the
geom_errorbar()
function with it to get the confidence
intervals to the plot. We created a dotplot with confidence intervals
with the below code.
library(ggplot2)
ggplot(data[data$group=='A',], aes(x, y)) +
geom_point() +
geom_errorbar(aes(ymin = lower, ymax = upper)) +
theme_bw()
We add a parameter so see dotplot for group A and B simultaneously.
ggplot(data, aes(x, y, col=group)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = lower, ymax = upper, col=group)) +
scale_color_manual(values = c("#0073C299","#8F770099")) +
theme_bw()
This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Based on The R Graph Gallery by Yan Holtz.