3

I have a question about how to hide(or remove) dots in the boxplot graph.

This is code what I implemented.

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

So I would like to hide(or remove) all of the event's dots (both of False and True).

However, I have no information about what I want.

Please let me know how to do it.

Thanks always.

enter image description here

hpesoj626
  • 3,529
  • 1
  • 17
  • 25
SJUNLEE
  • 167
  • 2
  • 14
  • 1
    Your question is closely related to [this one](https://stackoverflow.com/questions/50434608/remove-geoms-from-an-existing-ggplot-chart). You could do `p$layers[[2]] <- NULL` and/or `library(ggpmisc); delete_layers(p, "GeomPoint")`, where `p` is the name of your plot. – markus Jun 02 '18 at 19:48
  • @markus it's perfect!! thank you so much. – SJUNLEE Jun 03 '18 at 01:39

2 Answers2

3

I am not familiar how ggRandomForests work. But using the data frame gg_v, we can directly do the plotting in 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()

enter image description here

hpesoj626
  • 3,529
  • 1
  • 17
  • 25
0

You can also use the function "geom_boxplot2" from github ("Ipaper")

# 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()
learners
  • 195
  • 1
  • 12