Align the title of the legend of the two lines on the left with the expression ()

Using this script

df <- data.frame(x = 1:5, y = 1:5, color = letters[1:5])
ggplot(df, aes(x, y, fill = color)) +
  geom_point(size = 4, pch = 21) + 
  guides(fill = guide_legend(
     title = expression(atop(Median~Nitrate-Nitrogen~(NO[3]^{textstyle("-")}-N), ".\n Concentration"~(mg~L^{textstyle("-")})))))

I got this figure

enter image description here

Any suggestions for aligning the second line of the legend name on the left?

+6
source share
1 answer

quick and ugly answer, but it does the job until someone delivers a better one ...

ggplot(df, aes(x, y, fill = color)) +
  geom_point(size = 4, pch = 21) + 
  guides(fill = guide_legend(
    title = expression(atop(Median~Nitrate-Nitrogen~(NO[3]^{textstyle("-")}-N), "Concentration"~(mg~L^{textstyle("-")})~phantom (1000000)~phantom (1000000)))))
+5
source

Source: https://habr.com/ru/post/1014867/


All Articles