library(tidyverse)

# Example - Plot of a Distribution with a Shaded Area
########################################################################################

# Define the x-axis limits for the Plot
# ggplot needs a data table as argument
x_axis <- tibble(
  xlim = c(-4, 4)
)
ggplot(x_axis , aes(x = xlim)) +
  stat_function(fun = dnorm, args = list(mean = 0, sd = 1)) +
  stat_function(fun = dnorm, args = list(mean = 0, sd = 1),
                geom = "area", fill = "steelblue", alpha = .25, xlim=c(-4,0)) +
  labs(x = "Z", y = "Density")


# Example - Plots of Other Functions
########################################################################################

# Define the x-axis limits for the Plot
# ggplot needs a data table as argument
x_axis <- tibble(
  xlim = c(-10, 10)
)

# Plot of sin() (core R)
ggplot(x_axis , aes(x = xlim)) +
  stat_function(fun = sin)

# Self-defined function named x_squared
x_squared <- function(x) {x*x}

# Plot of x_squared() (self-defined)
ggplot(x_axis , aes(x = xlim)) +
  stat_function(fun = x_squared)
