2011-10-16 105 views
3

我在這裏錯過了什麼?沒有得到適當的傳奇標籤。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

回答

7

我看不出有任何需要使用plotmath粘貼:

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

加上幫助(plotmath)頁明確指出, 「\ n」 不玩好表達式。

+0

+1 Thanks DWin。這工作正常。 – MYaseen208