在 ggplot 中增加累积函数图中的线条大小

huangapple go评论59阅读模式
英文:

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?
在 ggplot 中增加累积函数图中的线条大小

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_buildlapply 来在每个图层中使用 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)

在 ggplot 中增加累积函数图中的线条大小

创建于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 = &quot;frailtypack&quot;)
readmission &lt;- subset(readmission, !(id %in% c(60, 109, 280)))
mcf0 &lt;- mcf(Recur(t.start %2% t.stop, id, event, death) ~ sex, data = readmission)
p &lt;- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20) 

q &lt;- ggplot_build(p)

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

q &lt;- ggplot_gtable(q)
plot(q)

在 ggplot 中增加累积函数图中的线条大小<!-- -->

<sup>Created on 2023-04-06 with reprex v2.0.2</sup>

Different linewidth:

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

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

q &lt;- ggplot_build(p)

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

q &lt;- ggplot_gtable(q)
plot(q)

在 ggplot 中增加累积函数图中的线条大小<!-- -->

<sup>Created on 2023-04-06 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年4月6日 21:10:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949920.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定