Re: [程式] R軟體: 有辦法在legend裡兩次使用bquot …

看板Statistics作者 (cc)時間13年前 (2011/08/05 23:32), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
難得有116學弟來問~ legend("bottomright", legend = c(as.expression(bquote(sigma[1] == .(sigma1))), as.expression(bquote(sigma[2] == .(sigma2)))), col=1:2, lty=1:2) 關鍵應該在這邊 其餘的你再調整囉 ※ 引述《yellowleaf (Mr.Smile)》之銘言: : [軟體程式類別]: : R : [程式問題]: : 繪圖 : [軟體熟悉度]: : 中(3個月到1年) : [問題敘述]: : 我希望能夠在legend中標兩條線,像下面這樣: : ─sigma = 1 : ─sigma = 2 : 以上的sigma想弄成希臘字母 1和2則是希望可以利用變數來設定他的值 : 本來想利用bquote這個函數 : 也只能做到標一條線 : 請問有人可以幫忙修正我的程式嗎?或者有什麼其他方法可以達到我的目的呢? : [程式範例]: : n1 <- 50 : n2 <- 50 : sigma1 <- 1 : sigma2 <- 2 : a <- rlnorm(n1,0,sigma1) : b <- rlnorm(n2,0,sigma2) : cdf.a <- ecdf(a) : cdf.b <- ecdf(b) : plot(cdf.a,col=2,main="Empirical CDF of Lognormal Samples") : plot(cdf.b,col=3,add=T) : legend("bottomright", legend= bquote(sigma == .(sigma1)), col=2, lty=1) : # 只有一條線 : legend(10,0.2, c(bquote(sigma == .(sigma1)), bquote(sigma == .(sigma2))), : col=c(2,3), lty=1) # 這我亂打的,顯然不對 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.38.194.57 ※ 編輯: acecc 來自: 114.38.194.57 (08/05 23:33)

08/06 00:16, , 1F
已解決 謝謝學長!!
08/06 00:16, 1F
文章代碼(AID): #1EF0qdm2 (Statistics)
文章代碼(AID): #1EF0qdm2 (Statistics)