- 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 change the angle of annotated text in plot created by using ggplot2 in R?
To annotate the text inside a plot created by ggplot2, we can use annotate function. It is used to give some explanation about the plot or add any useful information that will help readers to understand the plot in a better way. Sometimes, we might want to change the angle of the annotated text, especially in cases where we have some information that is presented vertically in the plot, therefore, we can use angle argument of the annotate function.
Example
Consider the below data frame −
> x<-runif(10,2,5) > y<-runif(10,5,6) > df<-data.frame(x,y) > df
Output
x y 1 4.086537 5.890591 2 2.271184 5.697052 3 3.335322 5.827102 4 2.155897 5.984699 5 4.054110 5.620492 6 3.936053 5.766108 7 4.341102 5.345369 8 2.450337 5.960743 9 4.992243 5.520061 10 2.776401 5.443892
Loading ggplot2 package and creating a plot with annotated text −
> library(ggplot2) > ggplot(df,aes(x,y))+geom_point()+annotate("text",x=3,y=5.4,label="ScatterPlot")
Output
Changing the angle of text “ScatterPlot” −
> ggplot(df,aes(x,y))+geom_point()+annotate("text",x=3,y=5.4,label="ScatterPlot",angle=9 0)
Output
- Related Articles
- How to align the text horizontally in a bar plot created by using ggplot2 in R?
- How to change legend values in a bar plot created by using ggplot2 in R?
- How to highlight text inside a plot created by ggplot2 using a box in R?
- How to make all text size same in a plot created by using ggplot2 in R?
- How to change the thickness of the borders of bars in bar plot created by using ggplot2 in R?
- How to change the size of dots in dotplot created by using ggplot2 in R?
- How to change the background color of a plot created by using plot function in R?
- How to add a citation in a plot created by using ggplot2 in R?
- How to change the abline colour created using ggplot2 in R?
- How to display regression slope using model in a plot created by ggplot2 in R?
- How to display regression intercept using model in a plot created by ggplot2 in R?
- How to change the Y axis limit for boxplot created by using ggplot2 in R?
- How to extract data from a plot created by ggplot2 in R?
- How to change the gridlines of Y-axis on a chart created by using ggplot2 in R?
- How to add a horizontal line to the plot created by ggplot2 in R?

Advertisements