我想添加一条曲线,其 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?
Run Code Online (Sandbox Code Playgroud)
谢谢,
设置freq = FALSE在直方图中绘制密度而不是频率,并使用points(或lines) 添加数据。
hist(expRandom, freq = FALSE)
points(x,y)
Run Code Online (Sandbox Code Playgroud)
您还可以y通过使用curve添加曲线来避免预先计算 值
hist(expRandom, freq = FALSE)
curve(dexp, from = 0, to = 10, add = TRUE)
Run Code Online (Sandbox Code Playgroud)
