英文:
Increasing size of lines in ggplot mean cumulative function plot
问题
我使用reReg包创建均值累积函数图,但无法更改图中线条的大小。有办法增加线条宽度吗?
英文:
I am using the reReg package to create mean cumulative function plots.
but I am unable to change the size of lines inside the plot.
is there anyway to increase the line width?
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)
Thanks for reading
答案1
得分: 2
你可以使用 ggplot_build
和 lapply
来在每个图层中使用 linewidth
,如下所示(我使用了较大的 linewidth
以显示结果):
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)
不同的 linewidth
:
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
英文:
You could use ggplot_build
to change the linewidth
in each layer with lapply
like this (I used big linewidth to show result):
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)
<!-- -->
<sup>Created on 2023-04-06 with reprex v2.0.2</sup>
Different linewidth:
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)
<!-- -->
<sup>Created on 2023-04-06 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论