- 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 change ordinal X-axis label to text labels using ggplot2 in R?
A plot created with ordinal values on X-axis needs to be ordered for plotting, otherwise, the plot will have continuous values on the X-axis that includes ordinal values. If we want to convert those values to text then scale_x_discrete should be used with the number of breaks, these number of breaks are the actual number of labels we want to use in our plot.
Example
Consider the below data frame −
x<-1:3 Quantity<-c(515,680,550) df<-data.frame(x,Quantity) library(ggplot2) ggplot(df,aes(x,Quantity))+geom_point()
Output
Plotting text labels on X-axis in place of numbers −
ggplot(df,aes(ordered(x),Quantity))+geom_point()+ + scale_x_discrete(breaks = 1:3, labels=c("Small","Medium","Large"))+ + xlab(NULL)
Output
- Related Articles
- How to change the color of X-axis label using ggplot2 in R?
- How to change the orientation and font size of x-axis labels using ggplot2 in R?
- How to display positive sign for X-axis labels in R using ggplot2?
- How to increase the X-axis labels font size using ggplot2 in R?
- How to X-axis labels to the top of the plot using ggplot2 in R?
- How to reverse the X-axis labels of scatterplot created by using ggplot2 in R?
- How to change the text size of Y-axis title using ggplot2 in R?
- How to set the X-axis labels in histogram using ggplot2 at the center in R?
- How to convert the X-axis label in a bar plot to italic using ggplot2 in R?
- How to create a boxplot using ggplot2 for single variable without X-axis labels in R?
- How to change the X-axis labels for boxplots created by using boxplot function in R?
- How to change the Y-axis title to horizontal using ggplot2 in R?
- How to change the adjustment of the plot title using ggplot2 to align it above the Y-axis labels in R?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- How to italicize boxplot label in R using ggplot2?

Advertisements