Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial italics, axis.text.x

Tags:

r

ggplot2

Aloha,

For the following bar graph:

x <- ggplot(foo, aes(x=variety, y=percent)) + geom_bar()

The following italicizes all of my x-axis text:

x + opts(axis.text.x=theme_text(face='italic'))

However, I would like to italicize only the species names, not the control.

levels(foo$variety)
"control"    "species1" "species2"     "species3" 

Any suggestions?

like image 606
Drosera aliciae Avatar asked Aug 02 '12 01:08

Drosera aliciae


People also ask

How do you italicize in ggplot2?

Example 2: Adding an italic Text to ggplot2 Plot. In this example, firstly we will be creating a data frame of 10 elements and plotting it with the help of ggplot() function in the ggplot2 library. And then with the annotate() function and passing the italic parameter in the fontface, we will add italic text to it.

How do you rotate text on X axis?

To rotate x-axis text labels, we use “axis. text. x” as argument to theme() function. And we specify “element_text(angle = 90)” to rotate the x-axis text by an angle 90 degree.

How do I remove text from Axis?

To remove a particular axis title, use element_blank() instead of element_text() , for the corresponding theme argument.

How do I make text italic in R?

To write text in italic font, use a single underscore or asterix before and after the text. To write text in bold font, use a double asterix or underscores before and after the text.


1 Answers

Try this example:

library(ggplot2)

ggplot(CO2, aes(y=uptake,x=Type, group=Type))+
  geom_point()+
  scale_x_discrete("Location", labels=expression(Quebec, italic(Mississippi)))

enter image description here

like image 178
sebastian-c Avatar answered Sep 20 '22 01:09

sebastian-c