我使用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這很有趣 –