【问题标题】:How to hide (or remove) dots in the boxplot graph?如何隐藏(或删除)箱线图中的点?
【发布时间】:2022-01-31 17:32:51
【问题描述】:

我有一个关于如何在箱线图中隐藏(或删除)点的问题。

这是我实现的代码。

install.packages("randomForestSRC") 
install.packages("ggRandomForests")

library(randomForestSRC) 
library(ggRandomForests)

data(pbc, package="randomForestSRC") 
pbc.na <- na.omit(pbc)

set.seed(123) 
rsf <- rfsrc(Surv(days,status)~., data=pbc.na, ntree=500, importance=T)

gg_v <- gg_variable(rsf, time = c(2000, 4000),
                    time.labels = c("2000 days", "4000 days"))

gg_v$stage <- as.factor(gg_v$stage)

plot(gg_v, xvar="stage", panel=T, points=F)+
  ggplot2::theme_bw() +
  ggplot2::geom_boxplot(outlier.shape=NA)+
  ggplot2::labs(y="Survival (%)")+
  ggplot2::coord_cartesian(ylim=c(-.01, 1.02)) 

所以我想隐藏(或删除)所有事件的点(False 和 True)。

但是,我没有关于我想要什么的信息。

请告诉我怎么做。

永远感谢。

【问题讨论】:

  • 您的问题与this one密切相关。您可以使用p$layers[[2]] &lt;- NULL 和/或library(ggpmisc); delete_layers(p, "GeomPoint"),其中p 是您的情节名称。
  • @markus 太完美了!!非常感谢。

标签: r ggplot2


【解决方案1】:

我不熟悉ggRandomForests 的工作原理。但是使用数据框gg_v,我们可以直接在ggplot2中进行绘图。

ggplot(gg_v, aes(stage, yhat, group = stage)) + 
  geom_boxplot(outlier.shape = NA) + 
  facet_wrap(~time, nrow = 2, strip.position = "right") + 
  ylab("Survival (%)") + 
  theme_bw()

【讨论】:

  • 哇...太棒了。我没有意识到“facet_wrap”这个功能。非常感谢。
【解决方案2】:

您也可以使用来自 github(“Ipaper”)的函数“geom_boxplot2

# devtools::install_github('kongdd/Ipaper')
library(Ipaper)
library(ggplot2)

ggplot(gg_v, aes(stage, yhat, group = stage)) + 
geom_boxplot2(width = 0.8, width.errorbar = 0.5)+ 
facet_wrap(~time, nrow = 2, strip.position = "right") + 
ylab("Survival (%)") + 
theme_bw()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-30
    • 2015-05-15
    • 2020-03-18
    • 2017-09-30
    相关资源
    最近更新 更多