How to italicize part (one or two words) of an axis title

霸气de小男生 提交于 2019-12-17 16:11:37

问题


Is there any way to change the style of part of an axis title while keep the rest part unchanged? In my case, How could I italicize
"bacteria X" in the y-axis title? To my knowledge, the command theme(axis.title.y=element_text(face="italic")) can only change the whole y-aixs title, is it?

ggplot(fig1,aes(x=cf,y=Freq,fill=Var1)) +
geom_bar(stat="identity") +
labs(x="Groups",y="No. of bacteria X isolates with corresponding types",fill="Var1") +
theme(axis.title.y=element_text(face="italic"))

回答1:


You could make an expression like this:

my_y_title <- expression(paste("No. of ", italic("bacteria X"), " isolates with corresponding types"))
.... + labs(y=my_y_title)



回答2:


I believe RFelber's suggestion is what you are after. Try this:

labs(x="Groups",
     y=expression('No. of'~italic(bacteria X)~'isolates with corresponding types'),
     fill="Var1")

I did not need to use the bquote() function. The tildes produce single spaces for terms that are outside of the quotes.



来源:https://stackoverflow.com/questions/32555531/how-to-italicize-part-one-or-two-words-of-an-axis-title

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!