Hi,
My issue is that I want to plot a distribution with sta_function, but with different parameters. On the legend I want to report the values, but since ggplot sorts the numbers in alphabetic order, 10 comes before 3. Do you know any solution for controlling the order in this situation?
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.6.3
ggplot(data.frame(x = c(0, 20))) +
stat_function(fun = dchisq, args = list(df = 1), aes(x = x, color = "1"), size = 1.5) +
stat_function(fun = dchisq, args = list(df = 3), aes(x = x, color = "3"), size = 1.5) +
stat_function(fun = dchisq, args = list(df = 6), aes(x = x, color = "6"), size = 1.5) +
stat_function(fun = dchisq, args = list(df = 10), aes(x = x, color = "10"), size = 1.5) +
stat_function(fun = dchisq, args = list(df = 15), aes(x = x, color = "15"), size = 1.5) +
stat_function(fun = dchisq, args = list(df = 99), aes(x = x, color = "99"), size = 1.5) +
labs(
y = "", x = ""
)
#> Warning: `mapping` is not used by stat_function()
#> Warning: `mapping` is not used by stat_function()
#> Warning: `mapping` is not used by stat_function()
#> Warning: `mapping` is not used by stat_function()
#> Warning: `mapping` is not used by stat_function()
#> Warning: `mapping` is not used by stat_function()
Created on 2020-09-22 by the reprex package (v0.3.0)
Reprex enclosed,
Thank you for your help in advance
Marcell