This question解釋瞭如何在圖中添加數學符號。但是,當文本應該存儲在數據框本身中時,這不起作用。這是出現在facet_wrap子圖的小方框中的文本的情況。如何在ggplot facet_wrap文本中添加數學符號?
這是一個可重現的例子。比方說,例如我有T和m³中的這些數據,我想畫一個這樣的情節。
library(ggplot2)
dtf <- data.frame(year = rep(1961:2010,2),
consumption = cumsum(rnorm(100)),
item = rep(c("Tea bags","Coffee beans"),each=50),
unit = rep(c("T","m^3"),each=50))
ggplot(data=dtf)+
geom_line(aes(x=year, y=consumption),size=1) +
ylab(expression(paste("Consumption in T or ",m^3))) +
scale_x_continuous(breaks = seq(1960,2010,10)) +
theme_bw() + facet_wrap(item~unit, scales = "free_y")
ylab(expression(m^3))
顯示正確的單元。我怎麼能在這個方面顯示類似的m³?
也許[此帖](http://stackoverflow.com/問題/ 37399450/parsed-labels-along-one-facet-axis-unparsed-labels-along-the-other)將會很有幫助。 – lmo