如何在ggforest()生成的gg图对象中找到标签来编辑其内容?

问题描述 投票:0回答:1

我生成了一个 ggforest 图(包:

survival
survminer

fit <- coxph(formula, data)
p <- ggforest(fit, data)

并且想要编辑(删除)图中的标签“gASV11PFS”

plot to be edited

我试图找到存储描述的变量

str(p, max.level = NA)
但它不显示该变量。

> str(p, max.level = NA)
List of 11
 $ data       : list()
  ..- attr(*, "class")= chr "waiver"
 $ layers     :List of 1
  ..$ :Classes 'LayerInstance', 'Layer', 'ggproto', 'gg' <ggproto object: Class LayerInstance, Layer, gg>
    aes_params: list
    compute_aesthetics: function
    compute_geom_1: function
    compute_geom_2: function
    compute_position: function
    compute_statistic: function
    computed_geom_params: list
    computed_mapping: NULL
    computed_stat_params: list
    constructor: call
    data: data.frame
    draw_geom: function
    finish_statistics: function
    geom: <ggproto object: Class GeomDrawGrob, GeomCustomAnn, Geom, gg>
        aesthetics: function
        default_aes: uneval
        draw_group: function
        draw_key: function
        draw_layer: function
        draw_panel: function
        extra_params: 
        handle_na: function
        non_missing_aes: 
        optional_aes: 
        parameters: function
        rename_size: FALSE
        required_aes: 
        setup_data: function
        setup_params: function
        use_defaults: function
        super:  <ggproto object: Class GeomCustomAnn, Geom, gg>
    geom_params: list
    inherit.aes: FALSE
    layer_data: function
    map_statistic: function
    mapping: NULL
    position: <ggproto object: Class PositionIdentity, Position, gg>
        compute_layer: function
        compute_panel: function
        required_aes: 
        setup_data: function
        setup_params: function
        super:  <ggproto object: Class Position, gg>
    print: function
    setup_layer: function
    show.legend: NA
    stat: <ggproto object: Class StatIdentity, Stat, gg>
        aesthetics: function
        compute_group: function
        compute_layer: function
        compute_panel: function
        default_aes: uneval
        dropped_aes: 
        extra_params: na.rm
        finish_layer: function
        non_missing_aes: 
        optional_aes: 
        parameters: function
        required_aes: 
        retransform: TRUE
        setup_data: function
        setup_params: function
        super:  <ggproto object: Class Stat, gg>
    stat_params: list
    super:  <ggproto object: Class Layer, gg> 
 $ scales     :Classes 'ScalesList', 'ggproto', 'gg' <ggproto object: Class ScalesList, gg>
    add: function
    add_defaults: function
    add_missing: function
    backtransform_df: function
    clone: function
    find: function
    get_scales: function
    has_scale: function
    input: function
    map_df: function
    n: function
    non_position_scales: function
    scales: list
    train_df: function
    transform_df: function
    super:  <ggproto object: Class ScalesList, gg> 
 $ guides     :Classes 'Guides', 'ggproto', 'gg' <ggproto object: Class Guides, gg>
    add: function
    assemble: function
    build: function
    draw: function
    get_custom: function
    get_guide: function
    get_params: function
    get_position: function
    guides: NULL
    merge: function
    missing: <ggproto object: Class GuideNone, Guide, gg>
        add_title: function
        arrange_layout: function
        assemble_drawing: function
        available_aes: any
        build_decor: function
        build_labels: function
        build_ticks: function
        build_title: function
        draw: function
        draw_early_exit: function
        elements: list
        extract_decor: function
        extract_key: function
        extract_params: function
        get_layer_key: function
        hashables: list
        measure_grobs: function
        merge: function
        override_elements: function
        params: list
        process_layers: function
        setup_elements: function
        setup_params: function
        train: function
        transform: function
        super:  <ggproto object: Class GuideNone, Guide, gg>
    package_box: function
    print: function
    process_layers: function
    setup: function
    subset_guides: function
    train: function
    update_params: function
    super:  <ggproto object: Class Guides, gg> 
 $ mapping    : Named list()
  ..- attr(*, "class")= chr "uneval"
 $ theme      :List of 136
  ..$ line                            : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ rect                            : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ text                            :List of 11
  .. ..$ family       : chr ""
  .. ..$ face         : chr "plain"
  .. ..$ colour       : chr "black"
  .. ..$ size         : num 14
  .. ..$ hjust        : num 0.5
  .. ..$ vjust        : num 0.5
  .. ..$ angle        : num 0
  .. ..$ lineheight   : num 0.9
  .. ..$ margin       : 'margin' num [1:4] 0points 0points 0points 0points
  .. .. ..- attr(*, "unit")= int 8
  .. ..$ debug        : logi FALSE
  .. ..$ inherit.blank: logi TRUE
  .. ..- attr(*, "class")= chr [1:2] "element_text" "element"
  ..$ title                           : NULL
  ..$ aspect.ratio                    : NULL
  ..$ axis.title                      : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ axis.title.x                    : NULL
  ..$ axis.title.x.top                : NULL
  ..$ axis.title.x.bottom             : NULL
  ..$ axis.title.y                    : NULL
  ..$ axis.title.y.left               : NULL
  ..$ axis.title.y.right              : NULL
  ..$ axis.text                       : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ axis.text.x                     : NULL
  ..$ axis.text.x.top                 : NULL
  ..$ axis.text.x.bottom              : NULL
  ..$ axis.text.y                     : NULL
  ..$ axis.text.y.left                : NULL
  ..$ axis.text.y.right               : NULL
  ..$ axis.text.theta                 : NULL
  ..$ axis.text.r                     : NULL
  ..$ axis.ticks                      : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ axis.ticks.x                    : NULL
  ..$ axis.ticks.x.top                : NULL
  ..$ axis.ticks.x.bottom             : NULL
  ..$ axis.ticks.y                    : NULL
  ..$ axis.ticks.y.left               : NULL
  ..$ axis.ticks.y.right              : NULL
  ..$ axis.ticks.theta                : NULL
  ..$ axis.ticks.r                    : NULL
  ..$ axis.minor.ticks.x.top          : NULL
  ..$ axis.minor.ticks.x.bottom       : NULL
  ..$ axis.minor.ticks.y.left         : NULL
  ..$ axis.minor.ticks.y.right        : NULL
  ..$ axis.minor.ticks.theta          : NULL
  ..$ axis.minor.ticks.r              : NULL
  ..$ axis.ticks.length               : 'simpleUnit' num 0points
  .. ..- attr(*, "unit")= int 8
  ..$ axis.ticks.length.x             : NULL
  ..$ axis.ticks.length.x.top         : NULL
  ..$ axis.ticks.length.x.bottom      : NULL
  ..$ axis.ticks.length.y             : NULL
  ..$ axis.ticks.length.y.left        : NULL
  ..$ axis.ticks.length.y.right       : NULL
  ..$ axis.ticks.length.theta         : NULL
  ..$ axis.ticks.length.r             : NULL
  ..$ axis.minor.ticks.length         : 'simpleUnit' num 0points
  .. ..- attr(*, "unit")= int 8
  ..$ axis.minor.ticks.length.x       : NULL
  ..$ axis.minor.ticks.length.x.top   : NULL
  ..$ axis.minor.ticks.length.x.bottom: NULL
  ..$ axis.minor.ticks.length.y       : NULL
  ..$ axis.minor.ticks.length.y.left  : NULL
  ..$ axis.minor.ticks.length.y.right : NULL
  ..$ axis.minor.ticks.length.theta   : NULL
  ..$ axis.minor.ticks.length.r       : NULL
  ..$ axis.line                       : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ axis.line.x                     : NULL
  ..$ axis.line.x.top                 : NULL
  ..$ axis.line.x.bottom              : NULL
  ..$ axis.line.y                     : NULL
  ..$ axis.line.y.left                : NULL
  ..$ axis.line.y.right               : NULL
  ..$ axis.line.theta                 : NULL
  ..$ axis.line.r                     : NULL
  ..$ legend.background               : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ legend.margin                   : 'margin' num [1:4] 0points 0points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ legend.spacing                  : 'simpleUnit' num 14points
  .. ..- attr(*, "unit")= int 8
  ..$ legend.spacing.x                : NULL
  ..$ legend.spacing.y                : NULL
  ..$ legend.key                      : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ legend.key.size                 : 'simpleUnit' num 15.4points
  .. ..- attr(*, "unit")= int 8
  ..$ legend.key.height               : NULL
  ..$ legend.key.width                : NULL
  ..$ legend.key.spacing              : 'simpleUnit' num 7points
  .. ..- attr(*, "unit")= int 8
  ..$ legend.key.spacing.x            : NULL
  ..$ legend.key.spacing.y            : NULL
  ..$ legend.frame                    : NULL
  ..$ legend.ticks                    : NULL
  ..$ legend.ticks.length             : 'rel' num 0.2
  ..$ legend.axis.line                : NULL
  ..$ legend.text                     :List of 11
  .. ..$ family       : NULL
  .. ..$ face         : NULL
  .. ..$ colour       : NULL
  .. ..$ size         : 'rel' num 0.857
  .. ..$ hjust        : NULL
  .. ..$ vjust        : NULL
  .. ..$ angle        : NULL
  .. ..$ lineheight   : NULL
  .. ..$ margin       : NULL
  .. ..$ debug        : NULL
  .. ..$ inherit.blank: logi TRUE
  .. ..- attr(*, "class")= chr [1:2] "element_text" "element"
  ..$ legend.text.position            : NULL
  ..$ legend.title                    :List of 11
  .. ..$ family       : NULL
  .. ..$ face         : NULL
  .. ..$ colour       : NULL
  .. ..$ size         : NULL
  .. ..$ hjust        : num 0
  .. ..$ vjust        : NULL
  .. ..$ angle        : NULL
  .. ..$ lineheight   : NULL
  .. ..$ margin       : NULL
  .. ..$ debug        : NULL
  .. ..$ inherit.blank: logi TRUE
  .. ..- attr(*, "class")= chr [1:2] "element_text" "element"
  ..$ legend.title.position           : NULL
  ..$ legend.position                 : chr "none"
  ..$ legend.position.inside          : NULL
  ..$ legend.direction                : NULL
  ..$ legend.byrow                    : NULL
  ..$ legend.justification            : chr "center"
  ..$ legend.justification.top        : NULL
  ..$ legend.justification.bottom     : NULL
  ..$ legend.justification.left       : NULL
  ..$ legend.justification.right      : NULL
  ..$ legend.justification.inside     : NULL
  ..$ legend.location                 : NULL
  ..$ legend.box                      : NULL
  ..$ legend.box.just                 : NULL
  ..$ legend.box.margin               : 'margin' num [1:4] 0points 0points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ legend.box.background           : list()
  .. ..- attr(*, "class")= chr [1:2] "element_blank" "element"
  ..$ legend.box.spacing              : 'simpleUnit' num 14points
  .. ..- attr(*, "unit")= int 8
  .. [list output truncated]
  ..- attr(*, "class")= chr [1:2] "theme" "gg"
  ..- attr(*, "complete")= logi TRUE
  ..- attr(*, "validate")= logi TRUE
 $ coordinates:Classes 'CoordCartesian', 'Coord', 'ggproto', 'gg' <ggproto object: Class CoordCartesian, Coord, gg>
    aspect: function
    backtransform_range: function
    clip: off
    default: FALSE
    distance: function
    expand: FALSE
    is_free: function
    is_linear: function
    labels: function
    limits: list
    modify_scales: function
    range: function
    render_axis_h: function
    render_axis_v: function
    render_bg: function
    render_fg: function
    setup_data: function
    setup_layout: function
    setup_panel_guides: function
    setup_panel_params: function
    setup_params: function
    train_panel_guides: function
    transform: function
    super:  <ggproto object: Class CoordCartesian, Coord, gg> 
 $ facet      :Classes 'FacetNull', 'Facet', 'ggproto', 'gg' <ggproto object: Class FacetNull, Facet, gg>
    compute_layout: function
    draw_back: function
    draw_front: function
    draw_labels: function
    draw_panels: function
    finish_data: function
    init_scales: function
    map_data: function
    params: list
    setup_data: function
    setup_params: function
    shrink: TRUE
    train_scales: function
    vars: function
    super:  <ggproto object: Class FacetNull, Facet, gg> 
 $ plot_env   :<environment: 0x7fbdc486a828> 
 $ layout     :Classes 'Layout', 'ggproto', 'gg' <ggproto object: Class Layout, gg>
    coord: NULL
    coord_params: list
    facet: NULL
    facet_params: list
    finish_data: function
    get_scales: function
    layout: NULL
    map_position: function
    panel_params: NULL
    panel_scales_x: NULL
    panel_scales_y: NULL
    render: function
    render_labels: function
    reset_scales: function
    resolve_label: function
    setup: function
    setup_panel_guides: function
    setup_panel_params: function
    train_position: function
    super:  <ggproto object: Class Layout, gg> 
 $ labels     : list()
 - attr(*, "class")= chr [1:2] "gg" "ggplot"

如何找到标签的存储位置并进行编辑?

我也尝试过:

p + geom_label(show.legend = NA)
p + geom_text(show.legend = NA)

但这并没有改变任何事情。

作为示例,您可以尝试:

fit <- coxph(Surv(time, status) ~ age, data = lung)
p <- ggforest(fit, data = lung)
p

在示例中,标签“age”将在

p

中编辑
r ggplot2 plot survival survminer
1个回答
0
投票

只需在数据上更改它就容易得多。 改编自

ggforest
的帮助中的示例:

# Original
model <- coxph( Surv(time, status) ~ sex + rx + adhere, data = colon )
ggforest(model)

Original plot

# Edited
names(colon)[4] <- "Lorem ipsum"
model <- coxph( Surv(time, status) ~ `Lorem ipsum` + rx + adhere, data = colon )
ggforest(model)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.