How to set Hex color in stat_function

Hi! I have a question.
When I am using stat_function, there is an option to change colour depending on the geom choose (i.e fill or colour). However, when I plotted one of those, the colour is not what I chose. Is there something wrong with the package?

df <- tibble(x = c(20, 20))
df %>% 
ggplot(aes(x = x)) + 
 xlim(c(0 , 12)) + 
 stat_function(fun=dtri, args = list(min = 1,max = 7, mode = 5), geom = "area", 
               fill = "blue", alpha = 0.5)+
 labs(title = 'Triangular Distribution') + 
 theme(plot.title = element_text(size = 40, face = "bold", hjust = 0.5)) 

df %>% 
ggplot(aes(x = x)) + 
 xlim(c(0 , 12)) + 
 stat_function(fun=dtri, args = list(min = 1,max = 7, mode = 5), geom = "area", 
               fill = "#174C70", alpha = 0.5)+
 labs(title = 'Triangular Distribution') + 
 theme(plot.title = element_text(size = 40, face = "bold", hjust = 0.5)) 


I tried to use scale_fill_manual with no results.
Regards

I would do the color comparison without setting alpha. It makes a big difference in the apparent color.

library(ggplot2)
DF <- data.frame(X = 1:10, Y = rep(1, 10), Alph = seq(0.1, 1, 0.1))
ggplot(DF, aes(X, Y, alpha = Alph)) + geom_tile(fill = "#174C70", color = "white")

Created on 2020-06-12 by the reprex package (v0.3.0)

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