R中

R中

问题描述:

启动的图形结果让我们说我有以下代码:R中

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)我得到如下:enter image description here

我可以编辑什么绘制?例如,我想摆脱右侧的图形,将标题从'直方图'改为'香蕉直方图',并在同一图表上得到results_qsec和results_wt的直方图。 可以这样做吗?我看着启动文档,但找不到任何有用的东西。 谢谢 托尼

这个怎么样?当然,您可以更改纸盒宽度等,使其看起来更像原稿。

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") 

enter image description here

+1

我正要张贴一样的... –

感谢,看起来不错。 我找到了另一种方式,用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)) 
+0

这本质上是完全一样的东西,只是用ggplot,而不是基地。实际上我几乎发布了一个ggplot答案,但假设你想要的东西看起来类似于你提供的输出。 –