source('https://myweb.uiowa.edu/pbreheny/7110/f20/notes/fun.R')

# Uniform convergence figure
xx <- seq(0, 2, len=101)
f <- function(x, n) {
  if (missing(n)) {
    return(1*(x > 1))
  } else {
    (x <= 1)*x^n + (x > 1)
  }
}
plot(xx, f(xx, 1), type='n', bty='n', xlab='x', ylab='f(x)', las=1, ylim=c(-0.1, 1.1))
polygon(c(0, 1, 1, 0), c(-0.05, -0.05, 0.05, 0.05), border=NA, col='gray')
polygon(c(1, 2, 2, 1), c(0.95, 0.95, 1.05, 1.05), border=NA, col='gray')
lines(xx, f(xx, 1), lwd=2, col=pal(2)[2])
lines(xx, f(xx, 2), lwd=2, col=pal(2)[2])
lines(xx, f(xx, 5), lwd=2, col=pal(2)[2])
lines(0:1, c(0, 0), lwd=3)
lines(1:2, c(1, 1), lwd=3)
