2013-08-07 30 views
5

我想使用plotmathggplot2圖中創建一個包含前導上標的軸。上軸標籤創建標工作得很好,就像這樣:在plotmath表達式中帶前標(w/ggplot2)

require(ggplot2) 
ggplot(mtcars, aes(x=disp, y=mpg)) + 
    geom_point() + 
    ylab(expression(x[y])) 

enter image description here

不過,我想有我軸線標籤中讀取「Y(上標)X」 - 在邏輯上,這將是^yx,但這將不會解析:

Error: unexpected '^' in: " 
geom_point() + 
ylab(expression(^" 

有沒有辦法在語句的開頭強制上標?

回答

8

如何:

ggplot(mtcars, aes(x=disp, y=mpg)) + 
    geom_point() + 
    ylab(expression(phantom(0)^y * x)) 

我確信一定有辦法做到一個「佔位」的性格,但我不得不倒有幾分滾動?plotmath找到它。

+4

也許可以使用一個空的加倍報價。 '表達式(「」^ y * x)「 –