coloring the area under a curve for multiple plots in R

拜拜、爱过 提交于 2020-05-28 07:17:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!