- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 change the color of X-axis label using ggplot2 in R?
The default color of labels is black but we might want to change that color to something else so that we can get attention of the viewer to the labels if it is needed. To change the color of X-axis label using ggplot2, we can use theme function that has axis.title.x argument which can be used for changing the color of the label values.
Example
Consider the below data frame −
x<−rnorm(20,5,0.25) y<−rnorm(20,5,0.004) df<−data.frame(x,y) df
Output
x y 1 5.030380 4.997751 2 5.240119 4.998680 3 4.544677 4.999195 4 4.858193 4.998952 5 5.071308 5.001092 6 5.512129 4.998037 7 5.236292 5.002558 8 5.081739 5.001903 9 4.940688 5.005155 10 4.437274 5.002876 11 5.472674 4.997229 12 4.813980 5.005284 13 4.859050 4.993907 14 5.353379 4.998850 15 5.537771 4.988465 16 5.302592 4.999421 17 5.486402 4.991891 18 5.121558 5.003857 19 4.908864 5.003393 20 5.137028 5.008340
Loading ggplot2 package and creating a scatterplot −
Example
library(ggplot2) ggplot(df,aes(x,y))+geom_point()
Output
Creating the scatterplot with X-axis label in red color −
Example
ggplot(df,aes(x,y))+geom_point()+theme(axis.title.x=element_text(colour="red"))
Output
- Related Articles
- How to change ordinal X-axis label to text labels using ggplot2 in R?
- Change the color of X-axis line for a graph using ggplot2.
- How to convert the X-axis label in a bar plot to italic using ggplot2 in R?
- How to change the orientation and font size of x-axis labels using ggplot2 in R?
- How change the color of facet title using ggplot2 in R?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- How to change the color of points for ggplot2 scatterplot using color brewer in R?
- How to change the color of points in a scatterplot using ggplot2 in R?
- How to change the Y-axis title to horizontal using ggplot2 in R?
- Change the color of legend element border using ggplot2 in R.
- How to change the text size of Y-axis title using ggplot2 in R?
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to change the color of lines for a line chart using ggplot2 in R?
- How to X-axis labels to the top of the plot using ggplot2 in R?
- How to change the axis color in base R plot?

Advertisements