Description Usage Arguments Details Author(s) See Also Examples
quantileLines
Adds line segments at the requested quantiles of the x and y variables.
This is a useful addition to a paired scatterplot, to illustrate how observations are linked between conditions.
The quantile lines are set as the lowest layer, so they won't obscure the original paired scatterplot.
Adapted from the plot_quartile_bars function in the rogme package.
1 2 3 | quantileLines(p, probs = c(0.25, 0.5, 0.75), colour_m = "darkgrey",
colour = "grey", size_m = 0.5, size = 0.25, linetype_m = "dashed",
linetype = "dashed")
|
p |
the ggplot object to which the quantile lines should be added. |
probs |
numeric vector of probabilities with values in [0,1]. |
colour_m |
character indicating the colour of the middle line. |
colour |
character indicating the colour of the other lines. |
size_m |
numeric indicating the thickness of the middle line. |
size |
numeric indicating the thickness of the other lines. |
linetype_m |
character indicating the linetype of the middle line. |
linetype |
character indicating the linetype of the other lines. |
In order for these quantile lines to make sense, the axes of the plot should be identically scaled.
Frank H. Hezemans, Frank.Hezemans@mrc-cbu.cam.ac.uk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | library(ggplot2)
library(UsingR) # Package contains dataset
# Get data
data <- crime
# Create paired scatterplot
paired_scatter <- ggplot(data = data, aes(x = y1983, y = y1993)) +
geom_abline(slope = 1, intercept = 0) +
geom_point(shape = 21, fill = "grey") +
xlim(0, 1500) + ylim(0, 1500) +
labs(title = "Violent crime in 50 U.S. states in 1983 and 1993",
subtitle = "Rates per 100,000 population",
x = "Violent crime rate in 1983",
y = "Violent crime rate in 1993") +
theme_minimal() +
theme(aspect.ratio = 1)
# Add lines at the first quartile, median, and third quartile
paired_scatter <- quantileLines(paired_scatter, probs = c(0.25, 0.5, 0.75),
colour_m = "black", colour = "grey",
size_m = 0.5, size = 0.25,
linetype_m = "longdash", linetype = "dashed")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.