ggplot2中的图例标签

时间:2011-10-16 20:50:36

标签: r ggplot2

我在这里缺少什么?没有得到合适的传奇标签。

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

1 个答案:

答案 0 :(得分:7)

我认为没有必要使用plotmath-paste:

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

另外,帮助(plotmath)页面清楚地表明“\ n”与表达式不相符。