right/left skewed normal distribution curve in R and shading the area?

I do not understand what is the problem. My previous code seems to work fine, if I guess correctly what you want to do. I can not be sure, as I do not know what does shadenorm do, or which package contains this function. Here's an example with base graphics, and you can switch to ggplot2 if you prefer.

library(sn)
#> Loading required package: stats4
#> 
#> Attaching package: 'sn'
#> The following object is masked from 'package:stats':
#> 
#>     sd

values <- seq(from = -1,
              to = 2,
              by = 0.01)
densities <- dsn(x = values,
                 xi = 0.1,
                 omega = 0.3,
                 alpha = 5)

plot(x = values,
     y = densities,
     type = "l")
abline(v = 0.2)
polygon(x = c(min(values), values[values < 0.2], 0.2),
        y = c(0, densities[values < 0.2], 0),
        border = NA,
        col = adjustcolor(col = "blue",
                          alpha.f = 0.5))

If this does not help, please provide a reproducible example. And please take a look here:

1 Like