# SCI Figure Hub — Stacked XRD Diffraction Patterns + Standard PDF Sticks (CC0-1.0) library(ggplot2) pal <- c("#3C5488", "#00A087", "#E64B35") tt <- seq(10, 80, length.out = 1000) lorentz <- function(x, x0, amp, w = 0.45) amp * (w^2 / ((x - x0)^2 + w^2)) peaks <- data.frame(pos = c(25.3, 37.8, 48.0, 53.9, 62.7), amp = c(1.0, 0.32, 0.45, 0.28, 0.26), hkl = c("(101)", "(004)", "(200)", "(105)", "(204)")) make_curve <- function(shift, offset, name) { y <- Reduce(`+`, Map(function(p, a) lorentz(tt, p + shift, a), peaks$pos, peaks$amp)) data.frame(two_theta = tt, intensity = y + offset, sample = name) } df <- rbind(make_curve(0, 0.55, "Pristine"), make_curve(0.18, 1.7, "Doped-5%"), make_curve(-0.15, 2.85, "Composite")) p <- ggplot(df, aes(x = two_theta, y = intensity, colour = sample)) + geom_segment(data = peaks, aes(x = pos, xend = pos, y = 0, yend = amp * 0.42), inherit.aes = FALSE, colour = "#475569", linewidth = 0.5) + geom_line(linewidth = 0.55) + scale_colour_manual(values = pal, name = NULL) + labs(x = expression(2*theta~"(degree)"), y = "Intensity (a.u.)") + theme_classic(base_size = 8) + theme(axis.text.y = element_blank(), axis.ticks.y = element_blank(), legend.position = "top") ggsave("xrd_stack.pdf", p, width = 89, height = 74, units = "mm")