norm_shape <- function(gem1,gem2,st_afw1,st_afw2){
  if( st_afw1>0 & st_afw1 <Inf & st_afw2>0 & st_afw2 <Inf & -Inf<gem1 & gem1<Inf & -Inf<gem2 & gem2<Inf ){
    library(ggplot2)
    xlow <- min(gem1 - 4*st_afw1, gem2 - 4*st_afw2)
    xhigh <- max(gem1 + 4*st_afw1, gem2 + 4*st_afw2)
    tkx <- c(gem1, gem2)
    ymax <- max(1/(st_afw1*(sqrt(2*pi))), 1/(st_afw2*(sqrt(2*pi))))
    tky1 <- round(1/(st_afw1*(sqrt(2*pi))), 3)
    tky2 <- round(1/(st_afw2*(sqrt(2*pi))), 3)
    tky <- c(0, tky1, tky2)
    ylabel <- round(c(0, tky1, tky2), 2)
    if (gem1 <= gem2) {
      xblue <- (11*xlow + 5*xhigh)/16
      xred <- (5*xlow + 11*xhigh)/16
    }else{
      xblue <- (5*xlow + 11*xhigh)/16
      xred <- (11*xlow + 5*xhigh)/16
    }
    myfun1 <- function(x) {
      y<-dnorm(x, mean = gem1, sd = st_afw1)
      return(y)}
    myfun2 <- function(x) {
      y<-dnorm(x, mean = gem2, sd = st_afw2)
      return(y)}
    ggplot(data.frame(x = c(xlow, xhigh)), aes(x)) + 
      coord_cartesian(expand = FALSE, xlim = c(xlow, xhigh), ylim = c(0, 1.1*ymax)) +               stat_function(fun = myfun1, color = "blue") +
      stat_function(fun = myfun2, color = "red") +
      geom_segment(x=gem1, y=0, xend=gem1, yend=tky1, color = "blue", linetype = 2) +
      geom_segment(x=gem2, y=0, xend=gem2, yend=tky2, color = "red", linetype = 2) +
      
      annotate("text", x = xblue, y =1.04*ymax , size = 4.5, label = bquote( ~ mu == .(gem1) ~ "en" ~ sigma ==.(st_afw1)) , color = "blue") +
      
      annotate("text", x = xred, y =1.04*ymax , size = 4.5, label = bquote( ~ mu == .(gem2) ~ "en" ~ sigma ==.(st_afw2)) , color = "red") +
      
      scale_x_continuous(breaks = tkx) +
      scale_y_continuous(breaks = tky, labels = ylabel) +    
      theme( 
        aspect.ratio = 0.70 ,
        axis.title.x = element_text(hjust = 1),
        axis.line.x = element_line(linewidth = 0.5, arrow = arrow(angle = 20, length = unit(0.4, "cm"))),
        axis.title.y = element_text(vjust = 1, angle =0))
  }else{
    cat("controleer of de getallen die \nje hebt ingevuld voldoen aan \n∙ - ∞ < gem1 < + ∞ \n∙ - ∞ < gem2 < + ∞  \n∙  0 < st_afw1 < + ∞ \n∙  0 < st_afw2 < + ∞")
  }
  }
  
