knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(ggthemr)
ggthemr("earth")R gist — Plotting the area under the curve with ggplot
Methods
x <- 1:11
y <- (1.5:11.5)^2
low <- (0:10)^2
upp <- (3:13)^2ggplot() +
aes(x, y) +
geom_line() +
geom_ribbon(aes(ymin = low, ymax = upp), alpha = 0.5)
x2 <- c(1:8, NA, NA, NA)
ggplot() +
aes(x, y) +
geom_line() +
geom_ribbon(aes(x = x2, ymin = low, ymax = upp), alpha = 0.5)
x <- seq(-4, 4, by = 0.05)
y <- dnorm(x)p <- ggplot() +
aes(x, y) +
geom_line()
p
p +
geom_ribbon(
aes(x = ifelse(x <= -1 , x, NA), ymin = 0, ymax = y),
fill = "#E84646",
alpha = 0.4
)
Citation
BibTeX citation:
@online{coretta2021,
author = {Coretta, Stefano},
title = {R Gist — {Plotting} the Area Under the Curve with Ggplot},
date = {2021-07-04},
url = {https://stefanocoretta.github.io/posts/2021-07-04-plotting-the-area-under-the-curve/},
langid = {en}
}
For attribution, please cite this work as:
Coretta, Stefano. 2021. R gist — Plotting the area under the curve with
ggplot. https://stefanocoretta.github.io/posts/2021-07-04-plotting-the-area-under-the-curve/.