2015-12-09 26 views
1

而不是在x標籤中添加數學符號,我試圖在0,40和40秒添加$ t_ [1,n] $,$ t_ [2,n] $和$ t_ [3,n] $符號。 x軸值分別爲85點。這樣做,我的代碼是是否可以在x軸值中添加數學符號?

m=c(rnorm(40,0,.5),rnorm(45,5,.5)); 
plot(rep(1:85,1), m, type="l", lty=1, xaxt='n', yaxt='n',ann=FALSE, col=4); 
windowsFonts(script=windowsFont("Script MT Bold")); 
title(xlab=c(expression(t[1,n]), expression(t[2,n]), expression(t[3,n])), family="script"); 

enter image description here

回答

0

使用axis而不是title

axis(side = 1, at = c(0, 40, 85), 
    labels = c(expression(t["1,n"]), 
       expression(t["2,n"]), 
       expression(t["3,n"]))) 
2

也許與ggplot2嘗試,喜歡這裏:

library("ggplot2") 

x <- 1:85 
y <- c(rnorm(40,0,.5), rnorm(45,5,.5)); 

dane <- data.frame(x=x, y=y) 

ggplot(dane, aes(x=x, y=y))+ 
    geom_line()+ 
    theme_bw()+ 
    scale_x_discrete(breaks=c(1, 40, 85), 
        labels=c(expression(t[paste("[", 1, ",", n, "]")]), 
           expression(t[paste("[", 2, ",", n, "]")]), 
           expression(t[paste("[", 3, ",", n, "]")]))) 
+0

謝謝!但我更喜歡在沒有任何包的情況下使用它。 +1這樣好的答案! – Adidul

相關問題