- 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 represent all values of X-axis or Y-axis on the graph in R using ggplot2 package?
If we have many unique elements or repeated in a column of an R data frame and create a graph using that column, either on X-axis or Y-axis then R automatically choses the axes labels, this might not display all the unique values of the column in the plot. Therefore, we can use scale_x_continuous function or scale_y_continuous function with labels depending on our requirement to display the column values.
Consider the below data frame −
Example
x<-1:10 y<-rpois(10,2) df<-data.frame(x,y) df
Output
x y 1 1 1 2 2 1 3 3 5 4 4 3 5 5 3 6 6 0 7 7 2 8 8 5 9 9 2 10 10 4
Loading ggplot2 package and creating a point chart between x and y by displaying all values of x axis −
Example
library(ggplot2) ggplot(df,aes(x,y))+geom_point()+scale_x_continuous(labels=as.character(x),breaks=x)
Creating a point chart between x and y by displaying all values of Y axis −
Example
ggplot(df,aes(x,y))+geom_point()+scale_y_continuous(labels=as.character(y),breaks=y)
- Related Articles
- Create ggplot2 graph with reversed Y-axis and X-axis on top in R.
- How to increase the length of Y-axis values for ggplot2 graph in R?
- How to plot values with log scales on x and y axis or on a single axis in R?
- How to change the Y-axis values in a bar plot using ggplot2 in R?
- How to display 0 at Y-axis using ggplot2 in R?
- How to display count on Y-axis for line chart using ggplot2 in R?
- How to set the Y-axis tick marks using ggplot2 in R?
- How to create a histogram with Y-axis values as count using ggplot2 in R?
- How to change the Y-axis title to horizontal using ggplot2 in R?
- How to change the color of X-axis label using ggplot2 in R?
- How to change the gridlines of Y-axis on a chart created by using ggplot2 in R?
- How to change the text size of Y-axis title using ggplot2 in R?
- How to create cumulative sum chart with count on Y-axis in R using ggplot2?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- How to display Y-axis with Euro sign using ggplot2 in R?

Advertisements