为什么ggtheme无法在ggsurvplot / R中打印?

时间:2019-05-15 08:07:18

标签: r ggplot2

已解决:需要更新软件包

请在下面找到My Data

我绘制了无进展生存期和总生存期的Kaplan-Meier组合图。

我使用了以下脚本

pfs <- survfit(Surv(resp.time, response) ~ 1, conf.type="log", data=w)
os <- survfit(Surv(Follow.up.death, Death) ~ 1, conf.type="log", data=w)

fit <- list(PFS = pfs, OS = os)
ggsurvplot(fit, data = w, combine = TRUE, 
           risk.table = TRUE,                  
           conf.int = TRUE,                    
           conf.int.style = "ribbon",            
           censor = TRUE,                     
           tables.theme = theme,
           ggtheme = theme,
           xlim = c(0,36),
           ylim = c(0.25,1),
           alpha=0.8,
           size=0.7,
           conf.int.alpha=c(0.1),
           break.x.by = 6,
           palette = c("#1C73C2","red"))

哪个给了

enter image description here

如您所见,我设计了自己的“主题”,由:

theme <- theme(axis.line = element_line(colour = "black"),
               panel.grid.major = element_line(colour = "gray98"),
               panel.grid.minor = element_line(colour = "gray98"),
               panel.border = element_blank(),
               panel.background = element_blank())

似乎在打印图时,theme仅添加到表中,而ggtheme=theme则不添加到图本身。

我可以像表中那样以某种方式将theme添加到绘图中吗?

My Data

的示例
w <- structure(list(WHO = c(1L, 3L, 2L, 2L, 2L, 3L, 2L, 3L, 1L, 2L, 
3L, 3L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 4L, 4L, 1L, 4L, 1L, 2L, 1L, 4L, 1L, 4L, 4L, 4L, 
4L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 4L, 4L, 2L, 1L, 2L, 2L, 4L, 4L, 
4L, 2L, 4L, 1L, 4L, 4L, 2L, 4L, 4L, 3L, 4L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L
), Death = c(0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 
1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 
0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L), Follow.up.death = c(18, 
2, 14, 17, 31, 4, 20, 15, 12, 19, 10, 17, 27, 22, 3, 43, 24, 
14, 13, 5, 12, 137, 22, 87, 48, 24, 72, 32, 14, 83, 68, 56, 57, 
18, 16, 70, 1.9, 69.2, 126.3, 41.6, 17.9, 1.3, 87.4, 4.4, 137.4, 
17.5, 95.8, 65.2, 14.8, 98.5, 16.6, 74.9, 10.3, 43.4, 32.5, 4.8, 
7.3, 107.8, 6.8, 18.3, 33, 25.2, 49.2, 15.9, 1.2, 42.7, 1, 9, 
1.8, 15.6, 8.9, 15, 16.4, 7.7, 75.5, 12.2, 54.8, 22.2, 9.7, 14.3, 
5.2, 64.5, 21.8, 0.2, 7.3, 18.7, 5.1, 17.3, 27.4, 16, 24.2, 9.7, 
8.2, 5.7, 41.8, 10.6, 22.8, 4.8, 6, 4, 50, 21, 30, 5, 11, 12), 
    response = c(0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 
    1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0L, 0L, 
    0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 
    0L, 0L, 0L, 0L, 0L), resp.time = c(18, 2, 13, 17, 22, 2, 
    6, 5, 12, 8, 3, 2, 1, 21, 2, 43, 4, 2, 4, 5, 0.1, 137, 4, 
    87, 17, 24, 72, 19, 14, 83, 68, 56, 57, 18, 14, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, 15.6, 8.9, 15, 16.4, 7.7, 75.5, 3, 54.8, 22.2, 12, 14.3, 
    6, 12, 21.8, 6, 3, 12, 3, 6, 3, 3, 12, 9.7, 3, 3, 12, 3, 
    6, 3, 6, 4, 50, 21, 30, 5, 11, 12)), .Names = c("WHO", "Death", 
"Follow.up.death", "response", "resp.time"), class = "data.frame", row.names = c(NA, 
-106L))

2 个答案:

答案 0 :(得分:1)

我认为主要和次要网格线都在那里,只是令人难以置信的微弱和/或导出设置中的某些内容,意味着导出的图像不够详细,无法显示它们。

使用您的代码,修改一些参数:

theme <- theme(axis.line = element_line(colour = "green"),
               panel.grid.major = element_line(colour = "red"),
               panel.grid.minor = element_line(colour = "blue"),
               panel.border = element_blank(),
               panel.background = element_blank())

enter image description here

使用:

theme <- theme(axis.line = element_line(colour = "black"),
               panel.grid.major = element_line(colour = "gray98"),
               panel.grid.minor = element_line(colour = "gray98"),
               panel.border = element_blank(),
               panel.background = element_rect(fill = "#BFD5E3", colour = "#6D9EC1"))

enter image description here

答案 1 :(得分:0)

那真的很奇怪。

这就是我得到的

theme <- theme(axis.line = element_line(colour = "black"),
               panel.grid.major = element_line(colour = "red"),
               panel.grid.minor = element_line(colour = "red"),
               panel.border = element_blank(),
               panel.background = element_blank())

csv

但我确实收到以下消息:警告消息:

1: Removed 1 rows containing missing values (geom_path). 
2: Removed 1 rows containing missing values (geom_path).