user8840683
user8840683

Reputation:

coloring the area under a curve for multiple plots in R

I was wondering if I could color the area under the same curves in my plots below?

library(lattice)
library(latticeExtra)

foo <- xyplot((1:32*.01)~wt|gear , data = mtcars)
foo + 
  layer(panel.densityplot(rnorm(1e3, 3.5), plot.points = FALSE))


# By color I mean like so: 
d <- density(rnorm(1e3, 3.5));
plot(d, type = 'n');
polygon(d, col = 2)

Upvotes: 1

Views: 76

Answers (1)

akrun
akrun

Reputation: 887851

We can use

library(lattice)
library(latticeExtra)    
d <- density(v1)
foo <- xyplot((1:32*.01)~wt|gear , data = mtcars)
foo +        
   layer(panel.polygon(d, col = 2, alpha = 0.3))

data

set.seed(24)
v1 <- rnorm(1e3, 3.5)

Upvotes: 0

Related Questions