ggplot 2中的多行标题,带有多个斜体字 [英] Multi line title in ggplot 2 with multiple italicized words

查看:563
本文介绍了ggplot 2中的多行标题,带有多个斜体字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在两行中手动格式化情节标题,其中包括两个斜体字,我已经完成了

解决方案

结合使用 atop paste 斜体 scriptstyle

  ggplot(mtcars,aes(x = wt,y = mpg))+ 
geom_point()+
labs (标题=〜atop(粘贴('第一行标题',italic(Species)),
粘贴(scriptstyle(italic(Species)),
scriptstyle(secondline words ),
scriptstyle(italic(anotherSpecies)),
scriptstyle(the end))))

为您提供期望的结果:



使用 scriptstyle 并不是必需的,但是imho将字幕放在比主标题更小的字体中更好。



另见?plotmath 用于其他有用的定制。


I am trying to create a plot title manually formatted on two lines which includes two italicized words, I have done some searching on Stack Exchange but have not found a good solution to this seemingly simple problem.

The scientific names of the two species are fairly long, and thus the need for a multi-line title (ggplot2 doesn't format this).

Objective:

..........First Line of Title with Species

Second line words anotherItalicSpecies the end

ggplot(mtcars,aes(x=wt,y=mpg))+
  geom_point()+
  labs(title= expression(paste(atop("First line of title with ", atop((italic("Species")))),"
       secondline words", italic("anotherSpecies"), "the end")))

Which yields the following mangled title:

解决方案

Using a combination of atop, paste, italic and scriptstyle:

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  labs(title = ~ atop(paste('First line of title with ',italic("Species")),
                      paste(scriptstyle(italic("Species")),
                            scriptstyle(" secondline words "),
                            scriptstyle(italic("anotherSpecies")),
                            scriptstyle(" the end"))))

gives you the desired result:

Using scriptstyle is not a necessity, but imho it is nicer to have your subtitle in a smaller font than the main title.

See also ?plotmath for other usefull customizations.

这篇关于ggplot 2中的多行标题,带有多个斜体字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆