::opts_chunk$set(echo = TRUE)
knitrlibrary(tidyverse)
library(ggthemr)
ggthemr("earth")
R gist — Plotting the area under the curve with ggplot
Methods
<- 1:11
x <- (1.5:11.5)^2
y <- (0:10)^2
low <- (3:13)^2 upp
ggplot() +
aes(x, y) +
geom_line() +
geom_ribbon(aes(ymin = low, ymax = upp), alpha = 0.5)
<- c(1:8, NA, NA, NA)
x2 ggplot() +
aes(x, y) +
geom_line() +
geom_ribbon(aes(x = x2, ymin = low, ymax = upp), alpha = 0.5)
<- seq(-4, 4, by = 0.05)
x <- dnorm(x) y
<- ggplot() +
p 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
)