ggplot stat_function scale_fill alpha trouble

Hi, I wanted to make the graph with alpha property and it seem to have trouble with it.
Here is my code:

Mean <- 0#mean(x)
SD <- 1#sd(x)
tblCol <- c(
           "#001010", 
           "#002020", 
           "#003131", 
           "#004141", 
           "#005252", 
           "#006262", 
           "#007373", 
           "#008383", 
           "#009494", 
           "#00A4A4", 
           "#00B4B4", 
           "#00C5C5", 
           "#00D5D5", 
           "#00E6E6", 
           "#00F6F6", 
           "#08FFFF"
)
Critical_Value <- qnorm(p = c(0, 
                              pnorm(q = -3, mean = Mean, sd = SD, lower.tail = TRUE),
                              pnorm(q = -2, mean = Mean, sd = SD, lower.tail = TRUE),
                              pnorm(q = -1, mean = Mean, sd = SD, lower.tail = TRUE),
                              pnorm(q = 0, mean = Mean, sd = SD, lower.tail = TRUE),
                              pnorm(q = 1, mean = Mean, sd = SD, lower.tail = TRUE),
                              pnorm(q = 2, mean = Mean, sd = SD, lower.tail = TRUE),
                              pnorm(q = 3, mean = Mean, sd = SD, lower.tail = TRUE),
                              1), mean = Mean, sd = SD)
df_Normal_Distribution <- data.frame(Z_Score = seq(from = -4, to = 4, by = 0.01))
df_Normal_Distribution %>%
  ggplot(mapping = aes(x = Z_Score)) +
  stat_function(
    n = 801,
    fun = dnorm,
    args = list(mean = Mean, sd = SD),
    geom = "area",
    color = alpha(tblCol[4], 0.785),
    aes(
      fill = after_stat(Z_Score) |> cut(!!Critical_Value),
      group = after_scale(fill)
    )
  ) +
  labs(title = "Cumulative Density Distribution",
       x = "Z_Score",
       y = "Probability Density") +
  guides(fill = "none") +
  scale_fill_manual(values = c(alpha("firebrick2", 0.785), 
                               alpha(tblCol[10], 0.785), 
                               alpha(tblCol[12], 0.785), 
                               alpha(tblCol[14], 0.785), 
                               alpha(tblCol[14], 0.785), 
                               alpha(tblCol[12], 0.785), 
                               alpha(tblCol[10], 0.785), 
                               alpha("firebrick1", 0.785))) +


Is there any way to make it more smooth?

If the ending colors ever match they get along together for some kind of reason, is there something wrong?

Unfortunately your code fails with an error:

Error in NROW(Z_Score) : object 'Z_Score' not found

Here I changed it sorry

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.