How to display two equal signs in R using ggplot2?


To display two equal signs using ggplot2, we can follow the below steps −

  • First of all, create a data frame.
  • Create a scatterplot(you can create any other plot).
  • Display two equal signs using annotate function

Create the data frame

Let's create a data frame as shown below −

 Live Demo

x<-sample(1:100,25)
y<-sample(1:100,25)
df<-data.frame(x,y)
df

On executing, the above script generates the below output(this output will vary on your system due to randomization) −

  x y
1 1 12
2 74 54
3 39 9
4 60 6
5 86 7
6 29 80
7 90 92
8 42 93
9 43 99
10 82 69
11 6  24
12 45 53
13 8  39
14 12 47
15 17 74
16 35 28
17 40 83
18 27 49
19 88 3
20 33 23
21 48 59
22 5  97
23 49 31
24 68 13
25 96 75

Create the scatterplot

Loading ggplot2 package and creating scatterplot between x and y −

x<-sample(1:100,25)
y<-sample(1:100,25)
df<-data.frame(x,y)
library(ggplot2)
ggplot(df,aes(x,y))+geom_point()

Output

Create scatterplot with two equal signs inside the plot

Use annotate function of ggplot2 package to display two equal signs inside the plot −

x<-sample(1:100,25)
y<-sample(1:100,25)
df<-data.frame(x,y)
library(ggplot2)
ggplot(df,aes(x,y))+geom_point()+annotate("text",x=75,y=75,label=(paste0("X==~Y==5
0")),parse=TRUE)

Output

Updated on: 13-Aug-2021

202 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements