Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
787 views
in Technique[技术] by (71.8m points)

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

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"))
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...