1

I make a plot of Cumulative distribution functions of seven distributions. However, it does not show all the elements of the legend. The plot looks like this:

result

The distribution does not show "Distribution" in full. Can anyone tell me how to solve this?

The code looks like this:

  ggplot(df, aes(x, colour = Distribution)) + stat_ecdf() + scale_color_discrete(labels = c("N(0, 2)", 'Laplace(0, 1)', 
                                  TeX("$0.85N(0, 0.2) + 0.15N(0, 20)$"), 
                                  'Gamma(0.05, 0.1)', 'Exp(0.9)', TeX("$F_{3, 8}$"), TeX("$P(mu_i=0) = 0.95, P(mu_i=8) = 0.05$"))) + 
  xlim(-3, 3) +
  xlab("Value") +
  ylab("Cumulative Density Function") + 
  theme(legend.text.align = 0, legend.position="bottom", legend.text=element_text(size=10))

Also, I do not want to change the position of legend. Because the plot can be too narrow if put the legend left or right side.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Simon
  • 15
  • 4
  • 3
    I think you mean that the full legend title, in this case "Distribution" does not show. Maybe try guides(fill=guide_legend(nrow=3)) to add another row and make more space for the legend title. – stomper Mar 14 '22 at 23:53
  • 1
    I tried guides(color=guide_legend(nrow=4, byrow=TRUE)) and it works. – Simon Mar 15 '22 at 02:07

0 Answers0