Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Legend label in ggplot2

Tags:

r

ggplot2

What I'm missing here? Not getting proper legend label.

p <- ggplot(mtcars, aes(factor(cyl), mpg))+ geom_boxplot(aes(fill = cyl))
p <- p + labs(fill=expression(paste("Temperature\n (", degree ~ F, " )")))
p

enter image description here

like image 903
MYaseen208 Avatar asked Apr 13 '26 16:04

MYaseen208


1 Answers

I do not see any need to use plotmath-paste:

 p <- ggplot(mtcars, aes(factor(cyl), mpg))+ geom_boxplot(aes(fill = cyl))
 p <- p + labs(fill=expression(atop("Temperature", ( degree~F))))
 p

Plus the help(plotmath) page makes clear that "\n" does not play well with expressions.

like image 90
IRTFM Avatar answered Apr 16 '26 09:04

IRTFM