R语言 增加ggplot中的线的大小

jfewjypa  于 2023-04-09  发布在  其他
关注(0)|答案(1)|浏览(124)

我正在使用rereg包来创建平均累积函数图。但我无法更改图中线条的大小。
有没有办法增加线宽?

library(reReg)
data(readmission, package = "frailtypack")
readmission <- subset(readmission, !(id %in% c(60, 109, 280)))
mcf0 <- mcf(Recur(t.start %2% t.stop, id, event, death) ~ sex, data = readmission)
p<- plot(mcf0, conf.int = TRUE)

p + theme_bw(base_size = 20)

感谢阅读

bpzcxfmw

bpzcxfmw1#

你可以使用ggplot_build来改变每一层中的linewidthlapply,就像这样(我使用大线宽来显示结果):

library(reReg)
library(ggplot2)
library(frailtypack)
data(readmission, package = "frailtypack")
readmission <- subset(readmission, !(id %in% c(60, 109, 280)))
mcf0 <- mcf(Recur(t.start %2% t.stop, id, event, death) ~ sex, data = readmission)
p <- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20) 

q <- ggplot_build(p)

q$data = lapply(q$data, \(x) {
  x$linewidth = 3
  x
})

q <- ggplot_gtable(q)
plot(q)

创建于2023-04-06带有reprex v2.0.2
不同线宽:

library(reReg)
library(ggplot2)
library(frailtypack)

p <- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20) 

q <- ggplot_build(p)

q$data = lapply(q$data, \(x) {
  x$linewidth = 1
  x
})

q <- ggplot_gtable(q)
plot(q)

创建于2023-04-06带有reprex v2.0.2

相关问题