I have a dataset named dataset as described below:
I am plotting the density plot using ggplot2.
I want to get those observations of the two group which overlaps in density plot.
| Observations | B | Group |
|---|---|---|
| Obs1 | 4 | Reference |
| Obs2 | 3 | Reference |
| Obs3 | 5 | Reference |
| Obs4 | 3 | Reference |
| Obs5 | 3 | Reference |
| Obs6 | 3 | User |
| Obs7 | 3 | User |
| Obs8 | 2 | User |
| Obs9 | 2 | User |
| Obs10 | 3 | User |
I have used these codes to plot the density plot: `
library(ggplot2)
library(plyr)
library(ggpubr)
#Importing dataset#
density_data <- read.csv("dataset.csv")
#Creating density plot between ref and user data, variable B#
g2 <- ggplot(density_data, aes(x=B, color=Group, fill= Group)) +
geom_density(color="black", alpha=0.9) + labs(x= "B", y= "Density")
g2

