我使用plotly绘制一个数据集的直方图我与密度曲线上plotly直方图
test <- data.frame(y = rgamma(1000, shape = 0.25, rate = 0.0054))
plot_ly(x = ~test$y, type = "histogram", nbinsx = "23")
情节本身是好的,但我不清楚如何绘制流过一个光滑的密度曲线工作直方图的轮廓。
Plotly reference manual表明,
直方图迹被初始化plot_ly或add_trace:
plot_ly(df, type="histogram"[, ...])
add_trace(p, type="histogram"[, ...])
和有我假设将允许用户绘制的密度曲线histnorm (enumerated: "" | "percent" | "probability" | "density" | "probability density")
histonorm功能,但我不知道如何使用这个功能。
有兴趣了解别人如何解决这个问题。任何提示或建议非常感谢。
我不知道如果一个方法可能是'scale'密度,使其上的情节更加清晰。 'test = data.frame(y = rgamma(1000,shape = 0.25,rate = 0.0054)); fit = density(test $ y); scale = 500/max(fit $ y); plot_ly()%>%add_histogram(x =〜test $ y,name =“直方图”)%>%add_lines(x = fit x,y = scale * fit $ y,name =“Density”)' –
@DarshanBaral这很有趣 –