主题标题中的斜体和正常文本

时间:2014-05-31 11:51:22

标签: r italics

我在R中绘制图形但是斜体函数在主标题下非常令人沮丧:

不同 C的映射区域。远园珊瑚礁遗址中的austriacus 个体

任何帮助都将不胜感激。

3 个答案:

答案 0 :(得分:17)

您没有提供有关您的数据的任何信息,但如果标题中的问题是斜体,则此代码可能有所帮助:

plot(rnorm(100), main = substitute(paste(italic('p value'), " = 0.01")))

enter image description here

另见this question

答案 1 :(得分:13)

我个人认为使用paste来构造plotmath表达式是“丑陋的”;这是一种替代方案,可以更清楚地展示expression的“干净”用法:

 plot(rnorm(100),main=expression( italic(p~value) == 0.01 ))

使用expression的另一个原因是它将被莱迪思函数接受,而substitute方法则不会:

xyplot(1~1,main=substitute( paste(italic('p value'), " = 0.01" )))
#Error in paste(italic("p value"), " = 0.01") : 
#  could not find function "italic"

如果在替代电话中使用expression()会成功,但在该情况下它是超重行李。我向Deepayan Sarkar抱怨过一次,他的回答是substitute返回了一个未经评估的“呼叫”,而不是真正的“表达”。

答案 2 :(得分:1)

I think other users have answered this, but I found it not so cut and dry, and built off of their input because it gets tricky for long titles like the one in your example.

Here is the cleanest line of code I could conjure for combined italic/normal texts, using a generic plot... let me know how it works for your data (or anyone who reads this and finds it doesn't work with certain graphs, inbox me, I enjoy learning and would rather share than just store it in my noggin)

plot(1:10, main = expression('Mapped territories of different '*italic(C.~austriacus)*' individuals at the Far Gardens coral reef site'))

Now, to line break with expression or like terms that allow italicized or superscript/subscript text (other than simple labels), you can use the atop function to evenly break apart super long labels. One may prefer to use the preview app for final editing and labels, but if you want to stick to R for everything, you can use the following example:

plot(1:10, main = expression(atop('Mapped territories of different '*italic(C.~austriacus),  ' individuals at the Far Gardens coral reef site')))

which gives: plot with long mixed title

Thanks to @42-