【问题标题】:Making an R histogram plot from a saved hist() call从保存的 hist() 调用中绘制 R 直方图
【发布时间】:2017-09-01 06:32:01
【问题描述】:

在R中,可以做到

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

可以进一步指定绘图类型,例如“h”或“s”。然而,这些看起来并不像一个正确的直方图。怎样才能用这种方式制作漂亮的直方图?

【问题讨论】:

  • 只要plot(hgram)
  • hist 函数本身提供了一种可以用plot 函数绘制的格式。如果您想操作和构建自己的直方图,您将需要您正在使用的参数,但这会比较棘手。
  • hist(x)ggplot2::qplot(x, bins = 9)
  • 您也可以使用highcharter 包进行绘图,如下所示:hgram %&gt;% hchart()

标签: r plot histogram


【解决方案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")

使用情节

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

绘图结果应在具有各种交互式控件的浏览器窗口中打开。更多情节功能可在其网站上获得: https://plot.ly/r/histograms/#normalized-histogram

【讨论】:

    猜你喜欢
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-23
    相关资源
    最近更新 更多