简体   繁体   English

为什么在R中绘制高密度点曲线的output不平滑?

[英]Why is the output of plotting a curve of high-density points in R not smooth?

This fact in basic R confuses me.基本 R 中的这一事实让我感到困惑。

I am plotting a count histogram of my data and then overlaying the shape of the gamma distribution that I think underlies the data.我正在绘制我的数据的计数直方图,然后覆盖我认为是数据基础的伽马分布的形状。 The points on the gamma distribution are generated using dgamma and plotted using curve .伽玛分布上的点是使用dgamma生成并使用curve绘制的。 No matter how many points I use to generate the curve, the output still looks pixellated.无论我使用多少点来生成曲线,output 仍然看起来像素化。 Does anyone know why and is it possible to obtain a smooth curve?有谁知道为什么以及是否有可能获得平滑的曲线?

dt <- rgamma(100, shape = 2.59, scale = 0.16)

n <- 1000
x <- seq(min(dt), max(dt), length.out = n) 

hist(dt, freq = FALSE, ylim = c(0, 2.5), xlab = "D")
curve(dgamma(x, shape = 2.59, scale = 0.16), add = TRUE, lwd = 2, n = n)

curve has a n attribute that defaults to 101 you need to increase that.曲线有一个n属性,默认为101 ,你需要增加它。 So note that not the datapoints you throw in determine your resolution.所以请注意,不是您输入的数据点决定您的分辨率。

curve(dgamma(x, shape = 2.59, scale = 0.16), add = TRUE, lwd = 2, n = n) # then it takes your defined n = 1000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM