- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert the X-axis label in a bar plot to italic using ggplot2 in R?
Obviously, the default font of axes-labels is not italic in R just like any other statistical analysis tool but we can make it using ggplot2. For this purpose, we can use theme function of ggplot2 package where we have an option to change the font of the axis labels using axis.text.x argument.
Example
Consider the below data frame:
> x<-c("A","B","C","D") > y<-c(24,23,25,27) > df<-data.frame(x,y) > df
Output
x y 1 A 24 2 B 23 3 C 25 4 D 27
Loading ggplot2 package and creating a bar plot:
Example
> library(ggplot2) > ggplot(df,aes(x,y))+geom_bar(stat="identity")
Output:
Creating bar plot with italic X-axis labels:
Example
> ggplot(df,aes(x,y))+geom_bar(stat="identity")+theme(axis.text.x=element_text(face=c("italic","italic","italic","italic"))) Warning message: Vectorized input to `element_text()` is not officially supported. Results may be unexpected or may change in future versions of ggplot2.
This warning message does not affect the plot but it helps us to understand that maybe the future versions of ggplot2 will not support vectorized input inside element_text.
Output:
- Related Articles
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- How to change the Y-axis values in a bar plot using ggplot2 in R?
- How to change the color of X-axis label using ggplot2 in R?
- How to represent X-axis label of a bar plot with greater than equal to or less than equal to sign using ggplot2 in R?
- How to change ordinal X-axis label to text labels using ggplot2 in R?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- How to X-axis labels to the top of the plot using ggplot2 in R?
- How to create transparent bar plot using ggplot2 in R?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to reverse the bars of a bar plot a using ggplot2 in R?
- How to display text in bar plot in the middle using ggplot2 in R?
- How to create bar plot with log values using ggplot2 in R?
- How to create a bar plot using ggplot2 with one bar having black border in R?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?

Advertisements