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

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

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

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

Thanks for reading

答案1

得分: 2

你可以使用 ggplot_buildlapply 来在每个图层中使用 linewidth,如下所示(我使用了较大的 linewidth 以显示结果):

  1. library(reReg)
  2. library(ggplot2)
  3. library(frailtypack)
  4. data(readmission, package = "frailtypack")
  5. readmission <- subset(readmission, !(id %in% c(60, 109, 280)))
  6. mcf0 <- mcf(Recur(t.start %2% t.stop, id, event, death) ~ sex, data = readmission)
  7. p <- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20)
  8. q <- ggplot_build(p)
  9. q$data = lapply(q$data, \(x) {
  10. x$linewidth = 3
  11. x
  12. })
  13. q <- ggplot_gtable(q)
  14. plot(q)

不同的 linewidth

  1. library(reReg)
  2. library(ggplot2)
  3. library(frailtypack)
  4. p <- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20)
  5. q <- ggplot_build(p)
  6. q$data = lapply(q$data, \(x) {
  7. x$linewidth = 1
  8. x
  9. })
  10. q <- ggplot_gtable(q)
  11. 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):

  1. library(reReg)
  2. library(ggplot2)
  3. library(frailtypack)
  4. data(readmission, package = &quot;frailtypack&quot;)
  5. readmission &lt;- subset(readmission, !(id %in% c(60, 109, 280)))
  6. mcf0 &lt;- mcf(Recur(t.start %2% t.stop, id, event, death) ~ sex, data = readmission)
  7. p &lt;- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20)
  8. q &lt;- ggplot_build(p)
  9. q$data = lapply(q$data, \(x) {
  10. x$linewidth = 3
  11. x
  12. })
  13. q &lt;- ggplot_gtable(q)
  14. plot(q)

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

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

Different linewidth:

  1. library(reReg)
  2. library(ggplot2)
  3. library(frailtypack)
  4. p &lt;- plot(mcf0, conf.int = TRUE) + theme_bw(base_size = 20)
  5. q &lt;- ggplot_build(p)
  6. q$data = lapply(q$data, \(x) {
  7. x$linewidth = 1
  8. x
  9. })
  10. q &lt;- ggplot_gtable(q)
  11. 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:

确定