从保存的hist()调用

时间:2017-09-01 06:32:02

标签: r plot histogram

在R中,可以做到

x <- rnorm(100, 0, 1) # generate some fake data
hgram <- hist(x, plot=F)
plot(hgram$mids, hgram$counts)

可以进一步指定情节类型,例如&#39; h&#39;或者&#39;。然而,这些看起来并不像一个合适的直方图。如何以这种方式制作漂亮的直方图?

1 个答案:

答案 0 :(得分:1)

考虑添加关于在R中制作体面直方图的输入(使用您的&#34; x&#34;来自您的问题)。

使用Base R

# histogram with colors and labels
hist(x, main = "Histogram of Fake Data", xlab = paste("x (units of measure)"), border = "blue", col = "green", prob = TRUE)
# add density
lines(density(x)) 
# add red line at 95th percentile
abline(v = quantile(x, .95), col = "red")

使用Plotly

install.packages("plotly")
library(plotly)
# basic Plotly histogram
plot_ly(x = x, type = "histogram")

图形结果应在具有各种交互式控件的浏览器窗口中打开。他们的网站提供了更多的图表功能: https://plot.ly/r/histograms/#normalized-histogram