- 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 create a graph in R using ggplot2 with all the four quadrants?
The default graph created by using ggplot2 package shows the axes labels depending on the starting and ending values of the column of the data frame or vector but we might want to visualize it just like we do in paper form of graphs that shows all of the four quadrants. This can be done by using xlim, ylim, geom_hline, and geom_vline functions with ggplot function of ggplot2 package.
Consider the below data frame −
Example
x<-1:5 y<-5:1 df<-data.frame(x,y) df
Output
x y 1 1 5 2 2 4 3 3 3 4 4 2 5 5 1
Loading ggplot2 package and creating point chart between x and y−
Example
library(ggplot2) ggplot(df,aes(x,y))+geom_point()
Output
Creating point chart between x and y by showing all four quadrants −
Example
ggplot(df,aes(x,y))+geom_point()+xlim(-6,6)+ylim(-6,6)+geom_hline(yintercept=0)+geom_vline(xintercept=0)
Output
- Related Articles
- How to create a horizontal bar graph using ggplot2 in R?
- Create a graph without background panel using ggplot2 in R.
- How to create a horizontal line in ggplot2 graph with larger width in R?
- How to create a horizontal line in ggplot2 graph with different color in R?
- How to create a ggplot2 graph in R without showing values?
- How to create a boxplot using ggplot2 with aes_string in R?
- How to create facetted plot with one facet displaying all data using ggplot2 in R?
- How to create a colored frame for ggplot2 graph in R?\n
- How to create a dashed horizontal line in a ggplot2 graph in R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create a scatterplot with two legends using ggplot2 in R?
- How to create a scatterplot with dark points using ggplot2 in R?
- How to display a variable with subscript ggplot2 graph in R?
- How to create stacked plot with density using ggplot2 in R?
- How to create histogram with varying binwidth using ggplot2 in R?

Advertisements