- Trending Categories
- Data Structure
- Operating System
- MS Excel
- 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 change the position of axes titles to top for X-variable and to right for Y-variable in R?
The default position of axes titles in any software or programming language for any 2D graph is bottom for X-axis and left for Y-axis but we might to change the position of these titles to top and right respectively. This can be done by using scale_x_continuous(position="top") and scale_y_continuous(position="right") functions of ggplot2 package.
Consider the below data frame −
set.seed(101) x<-rnorm(10,1) y<-rnorm(10,2) df<-data.frame(x,y) df
x y 1 0.6739635 2.52644810 2 1.5524619 1.20515556 3 0.3250562 3.42775554 4 1.2143595 0.53318031 5 1.3107692 1.76331662 6 2.1739663 1.80666204 7 1.6187899 1.15024526 8 0.8872657 2.05846550 9 1.9170283 1.18232964 10 0.7767406 -0.05030782
Loading ggplot2 package and creating a scatterplot between x and y −
Creating the scatterplot with y on right hand side and x on top of the graph −
- Related Articles
- How to display average line for y variable using ggplot2 in R?
- R Programing to change the name of column variable and row variable in xtab table.
- How to create horizontal line for Y variable at median in base R plot?
- How to create a lagged variable in R for groups?
- How to create vertical line for X variable at median in base R plot
- How to display base R plot axes titles in italics?
- How to create a point chart for categorical variable in R?
- How to create a boxplot using ggplot2 for single variable without X-axis labels in R?
- How to change the position of X-axis in base R plot?
- How to set the coefficient of one variable to 1 for logistic regression model in R?\n
- How to display the superscript for a single variable in a base R plot?
- How to set CLASSPATH variable for JDK?
- Python Plotly – How to change variable/label names for the legend in a line chart?
- How to create a frequency column for categorical variable in an R data frame?