我想添加一条曲线,它的x和y坐标已经定义为直方图。考虑下面的直方图:
set.seed(38593)
expRandom <- rexp(10000)
x <- seq(from = 0.05, to = 10, by = 0.001)
y <- exp(-x)
### Now I'd like to first draw my histogram and then
### add my plot(x,y) to my existing histogram:
hist(expRandom, freq = FALSE)
### ?? How to add my plot(x,y) to my histogram above?
谢谢,
答案 0 :(得分:4)
设置freq = FALSE
以绘制直方图中的密度而不是频率,并使用points
(或lines
)来添加数据。
hist(expRandom, freq = FALSE)
points(x,y)
您还可以使用y
添加曲线来避免预先计算curve
值
hist(expRandom, freq = FALSE)
curve(dexp, from = 0, to = 10, add = TRUE)