为R中的多个图着色曲线下的区域 [英] coloring the area under a curve for multiple plots in R

查看:50
本文介绍了为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)

推荐答案

我们可以使用

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))

数据

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

这篇关于为R中的多个图着色曲线下的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆