1

I am new to R. I wanted to get a two-tailed t-test shaded based on some specific ranges as illustrated below:

set.seed(100)
time_spent1 <- data.frame(time_spent=rnorm(1000, 500, 150))

mean1 <- mean(time_spent1$time_spent)
x1 <- runif(1,0,1000)
x2 <-250
p <- ggplot(time_spent1, aes(time_spent)) +
geom_density(fill="grey") +
geom_vline(xintercept=c(x1,x2)) 

d <- ggplot_build(p)$data[[1]]  

p <- p + geom_area(data = subset(d, x > x1), aes(x=x, y=y), fill="red") 

p

This code provides me the right tail shaded not the left tail. I appreciate any help to shade the left tail as well. Thanks

markus
  • 25,843
  • 5
  • 39
  • 58
Lue
  • 11
  • 2

0 Answers0