2017-04-22 89 views
2

較大的句子中改變顏色爲特定的一段文字,我不知道我怎麼會在下面的mtext()只更改的「20%」顏色如何R中

這裏是我的陰謀的圖片(請看圖片我下面的R代碼裏面):

enter image description here

這裏是我的R代碼裏面:

plot(1) 

a = .3 

b = .5 

mtext(side = 3, bquote(bold("There is:"~ bolditalic(.(paste(round((b - a)*100, 2), "%", 
    sep="")))~"probability that REAL effect size is equivalent to ZERO")), 
    cex = 1.3, xpd =T) 
+1

也許[這](http://stackoverflow.com/questions/17083362/colorize-parts-of-the-title-in-a-plot )或[這](http://stackoverflow.com/questions/20907421/how-to-give-different-colors-to-parts-of-the-main-of-a-plot)可以讓你開始。 –

+0

@StevenBeaupré,謝謝你,好像我的技巧更復雜,因爲它是一個複雜的數字。 – rnorouzian

回答

0

顯然,這不是確切的科學。最後,以下爲我工作:

plot(1) 

a = .3 ; b = .5 

mtext(side = 3, bquote(bold("There is:   probability that REAL effect size is equivalent to ZERO")), cex = 1.3, xpd =T) ## Notice the space 

mtext(side = 3, bquote(bolditalic(~.(paste(round((b - a)*100, 2), "%",sep="")))), line = .18, 
    cex = 1.3, xpd =T, col = 'red', adj = .12) ## Notice the "~" sign 

enter image description here

0

這絕對不是優雅的,但它可以工作(調整adj),如果你可以堅持固定的繪圖寬度。

plot(1) 
a = .3 
b = .5 

mtext(side = 3, line = 0.25, bquote(bold("There is:")), cex = 1.3, adj=0) 
mtext(side = 3, line = 0.25, bquote(bolditalic(.(paste0(round((b - a)*100, 2), "%")))), cex = 1.3, col ='red', adj=0.1) 
mtext(side = 3, line = 0.15, bquote(bold("probability that REAL effect size is equivalent to ZERO")), cex = 1.3, adj= 0.33)