- 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 increase the width of axes using ggplot2 in R?
To increase the width of axes (both X-axis and Y-axis at the same time) using ggplot2 in R, we can use theme function with axis.line argument where we can set element_line argument to a larger value.
Check out the Example given below to understand how it can be done.
Example
Following snippet creates a sample data frame −
x<-sample(0:9,20,replace=TRUE) y<-sample(0:9,20,replace=TRUE) df<-data.frame(x,y) df
The following dataframe is created
x y 1 6 9 2 7 8 3 1 3 4 2 4 5 1 2 6 2 5 7 2 4 8 1 6 9 4 1 10 7 6 11 0 8 12 9 0 13 9 4 14 1 8 15 6 5 16 7 7 17 0 0 18 6 7 19 1 6 20 6 8
To load ggplot2 package and create scatterplot between x and y on the above created data frame, add the following code to the above snippet −
x<-sample(0:9,20,replace=TRUE) y<-sample(0:9,20,replace=TRUE) df<-data.frame(x,y) library(ggplot2) ggplot(df,aes(x,y))+geom_point()
Output
If you execute all the above given snippets as a single program, it generates the following Output −
To create scatterplot between x and y with increased width of both the axes on the above created data frame, add the following code to the above snippet −
x<-sample(0:9,20,replace=TRUE) y<-sample(0:9,20,replace=TRUE) df<-data.frame(x,y) library(ggplot2) ggplot(df,aes(x,y))+geom_point()+theme(axis.line=element_line(size=2))
Output
If you execute all the above given snippets as a single program, it generates the following Output −
- Related Articles
- How to increase the axes tick width using ggplot2 in R?
- How to increase the width of the median line in boxplot using ggplot2 in R?
- How to increase the width of the lines in the boxplot created by using ggplot2 in R?
- How to increase the distance between boxplots using ggplot2 in R?
- How to extract axes labels for the plot drawn using ggplot2 in R?
- How to increase the space between horizontal legends using ggplot2 in R?
- How to display axes ticks and labels inside the plot using ggplot2 in R?
- How to increase the X-axis labels font size using ggplot2 in R?
- How to change the width of whisker lines in a boxplot using ggplot2 in R?
- How to increase the space between bars of a bar plot using ggplot2 in R?
- How to increase the width of the X-axis line for a ggplot2 graph?
- How to create a line chart using ggplot2 with larger width in R?
- How to create quantile regression plot with larger width of lines using ggplot2 in R?
- How to increase the length of Y-axis values for ggplot2 graph in R?
- R Programming how to display both axes’ labels of a ggplot2 graph in italics?
