- 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 display tilde ggplot2 graph in R?
Let’s say we want to display tilde sign at a particular position in histogram using ggplot2 graph. In this situation, we can use geom_text function and pass all the text with label argument inside aes where tilde will be written as %~%.
For Example, if we want to display X follows Normal Distribution then we can write it as −
geom_text(aes(label="X %~% Normal Distribution",x=0,y=200),parse=TRUE)
Here, x=0 and y=200 is the position of the label in the histogram.
Example
Consider the below data frame −
x<-rnorm(2000,5,2) df<-data.frame(x) head(df,20)
The following dataframe is created
x 1 3.429893 2 2.873259 3 4.621022 4 4.873246 5 4.707371 6 7.650049 7 6.402318 8 4.427331 9 6.830767 10 4.535618 11 6.622828 12 4.770918 13 1.018385 14 5.725048 15 2.238412 16 6.623515 17 4.835721 18 5.266638 19 5.380624 20 4.381922
To load the ggplot2 package and create histogram of x on the above created data frame, add the following code to the above snippet −
x<-rnorm(2000,5,2) df<-data.frame(x) library(ggplot2) ggplot(df,aes(x))+geom_histogram(bins=30)
Output
If you execute all the above given snippets as a single program, it generates the following Output −
To create a histogram of x with representing tilde sign in the graph on the above created data frame, add the following code to the above snippet −
x<-rnorm(2000,5,2) df<-data.frame(x) library(ggplot2) ggplot(df,aes(x))+geom_histogram(bins=30)+geom_text(aes(label="X %~% N(mu==5,sigma==2)",x=0,y=200),parse=TRUE)
Output
If you execute all the above given snippets as a single program, it generates the following Output −
- Related Articles
- How to display a variable with subscript ggplot2 graph in R?
- How to display data frame name in ggplot2 graph title in R?\n
- How to display mean line per group in facetted graph using ggplot2 in R?
- How to display NA frequency for a ggplot2 graph using color brewer in R?
- R Programming how to display both axes’ labels of a ggplot2 graph in italics?
- How to rotate a ggplot2 graph in R?
- How to convert ggplot2 graph into a plotly graph in R?
- How to add a caption in a ggplot2 graph in R?
- How to create a horizontal bar graph using ggplot2 in R?
- How to create a ggplot2 graph in R without showing values?
- How to display two equal signs in R using ggplot2?
- How to display legend on top using ggplot2 in R?
- How to display mean in a histogram using ggplot2 in R?
- How to create a colored frame for ggplot2 graph in R?\n
- How to display 0 at Y-axis using ggplot2 in R?
