- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 reverse the X-axis labels of scatterplot created by using ggplot2 in R?
There exists a possibility that one of the variables is recorded in an opposite manner and we want to create a scatterplot using that variable. Therefore, we would need to reverse that variable while plotting. Suppose that variable is an independent variable, hence it will be plotted on X-axis. Thus, to reverse the X-axis labels we can use scale_x_reverse function of ggplot2 package.
Consider the below data frame −
x<-rpois(20,5) y<-rpois(20,2) df<-data.frame(x,y) df
x y 1 5 1 2 7 0 3 5 1 4 7 3 5 3 1 6 3 2 7 0 4 8 8 1 9 7 3 10 8 3 11 3 2 12 5 4 13 8 2 14 2 0 15 3 1 16 6 3 17 4 0 18 4 2 19 3 1 20 8 3
Loading ggplot2 package and creating scatterplot between x and y −
Creating scatterplot between x and y with reversed limits −
- Related Articles
- How to change the X-axis labels for boxplots created by using boxplot function in R?
- 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 apply manually created x-axis labels in a histogram created by hist function in R?
- How to display positive sign for X-axis labels in R using ggplot2?
- How to create regression model line in a scatterplot created by using ggplot2 in R?
- How to change ordinal X-axis label to text labels using ggplot2 in R?
- How to change the orientation and font size of x-axis labels using ggplot2 in R?
- How to show all X-axis labels in a bar graph created by using barplot function in R?
- How to set the X-axis labels in histogram using ggplot2 at the center in R?
- How to change the Y axis limit for boxplot created by using ggplot2 in R?
- How to change the gridlines of Y-axis on a chart created by using ggplot2 in R?
- How to create a boxplot using ggplot2 for single variable without X-axis labels in R?
- How to label points in scatterplot created by using xyplot in R?
- How to display NA group values in scatterplot created with ggplot2 using color brewer in R?