2017-09-01 29 views
0

在R,一个可以做使从保存的HIST的R直方图()调用

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

一个可以进一步指定的曲线的类型,如“H”或“S”。然而,这些看起来并不像一个合适的直方图。如何用这种方式制作一个很好看的直方图?

+5

只是'plot(hgram)'。 –

+2

'hist'函数本身提供了一个可以用'plot'函数绘制的格式。如果你想操纵和建立你自己的直方图,你将需要你正在使用的参数,但这将是棘手的。 – R18

+0

'hist(x)'或'ggplot2 :: qplot(x,bins = 9)' – djhurio

回答

1

想到添加关于在R中制作像样的直方图的输入(使用您的问题中的“x”)。

使用基础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") 

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