问题
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)
回答1:
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)
来源:https://stackoverflow.com/questions/61644115/coloring-the-area-under-a-curve-for-multiple-plots-in-r