【问题标题】:graphing results of boot in R在 R 中绘制引导结果
【发布时间】:2017-09-15 07:07:13
【问题描述】:

假设我有以下代码:

library(boot)
samplemean <- function(x, d) {
  return(mean(x[d]))
}
results_qsec <- boot(data=mtcars$qsec, statistic = samplemean, R=1000)
results_wt <- boot(data=mtcars$wt, statistic = samplemean, R=1000)
plot(results_qsec)
plot(results_wt)

对于plot(results_wt),我得到以下信息:

我可以编辑绘制的内容吗?例如,我想去掉右边的图表,将标题从“t 直方图”更改为“香蕉直方图”,并将 results_qsec 和 results_wt 的直方图放在同一个图表上。 这可以做到吗?我查看了引导文档,但找不到任何有用的东西。 谢谢 托尼

【问题讨论】:

    标签: r plot


    【解决方案1】:

    这个怎么样?当然,您可以更改 bin 宽度等,使其看起来更像原始文件。

    wt_t <- plot(results_wt)$t
    sec_t <- plot(results_qsec)$t
    
    par(mfrow = c(1, 2))
    hist(wt_t, main = "banana")
    hist(sec_t, main = "apple")
    

    【讨论】:

      【解决方案2】:

      谢谢,看起来不错。 我找到了另一种方法,使用 ggplot:

      library(ggplot2)
      
      boot_qsec <- as.data.frame(results_qsec$t)
      boot_wt <- as.data.frame(results_wt$t)
      
      ggplot() + geom_histogram(data=boot_qsec,aes(V1)) + 
            geom_histogram(data=boot_wt ,aes(V1))
      

      【讨论】:

      • 这本质上是一模一样的,只是使用 ggplot 而不是 base。实际上,我几乎发布了一个 ggplot 答案,但假设您想要的东西看起来与您提供的输出相似。
      猜你喜欢
      • 2011-10-13
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      • 2020-01-05
      • 1970-01-01
      • 2021-06-04
      • 2016-07-22
      • 2020-11-30
      相关资源
      最近更新 更多