r - How to move the risktable legend text and title to the left in the plot with ggcuminc or survfit - Stack Overflow

I would like to to have the risktable title and risktable text to be positioned and aligned to the very

I would like to to have the risktable title and risktable text to be positioned and aligned to the very left as shown in the first picture.

Aim of cum inc plot

I have created an object:

library(survfit)
library(tidycmprsk)

fit.mh.male <- cuminc(Surv(time, status) ~ Exposure, data =  timesplit.mh.m)


fit.mh.male %>%
  ggcuminc()+
  add_risktable(
    risktable_stats = `n.risk`,
    stats_label = list(n.risk = "No. at Risk"), 
    size = 3)+
  add_confidence_interval()+
  scale_ggsurvfit()+
  labs(title = "FTMH male",
       x = "Time since surgery")+
  theme(axis.test.y = element_text(hjust = 1))+
  coord_cartesian(xlim = c(0, 10), 
                  ylim = c(0, 0.04)) + 
  scale_color_jama()+
  scale_fill_jama()+
  theme_minimal()+
  theme(legend.position = "bottom")+
  guides(color = guide_legend(nrow = 1))

In the code that I have, the risktable text is is aligned to the right - and it covers some of the numbers at risk at time = 0 and the risktable title is aligned over the number at time = 0, instead of being aligned over the risk table text.

My output of the code

I would like to to have the risktable title and risktable text to be positioned and aligned to the very left as shown in the first picture.

Aim of cum inc plot

I have created an object:

library(survfit)
library(tidycmprsk)

fit.mh.male <- cuminc(Surv(time, status) ~ Exposure, data =  timesplit.mh.m)


fit.mh.male %>%
  ggcuminc()+
  add_risktable(
    risktable_stats = `n.risk`,
    stats_label = list(n.risk = "No. at Risk"), 
    size = 3)+
  add_confidence_interval()+
  scale_ggsurvfit()+
  labs(title = "FTMH male",
       x = "Time since surgery")+
  theme(axis.test.y = element_text(hjust = 1))+
  coord_cartesian(xlim = c(0, 10), 
                  ylim = c(0, 0.04)) + 
  scale_color_jama()+
  scale_fill_jama()+
  theme_minimal()+
  theme(legend.position = "bottom")+
  guides(color = guide_legend(nrow = 1))

In the code that I have, the risktable text is is aligned to the right - and it covers some of the numbers at risk at time = 0 and the risktable title is aligned over the number at time = 0, instead of being aligned over the risk table text.

My output of the code

Share Improve this question edited Jan 17 at 5:13 marc_s 757k184 gold badges1.4k silver badges1.5k bronze badges asked Nov 18, 2024 at 10:20 BiromnieBiromnie 112 bronze badges 1
  • @ddsjoberg maybe you know how to solve this? – Biromnie Commented Nov 18, 2024 at 10:26
Add a comment  | 

1 Answer 1

Reset to default 0

To understand the problem better, it is vital to realise that the print method for a ggcuminc object creates two ggplot objects: the main panel at the top with the curves, and a little text-only ggplot at the bottom that acts as the risk table. The label "No. at Risk" is the title of the bottom plot, and the labels "Cataract" and "Victrectomy" are the y axis labels.

Using this information, we can pass the arguments to move these elements as a theme object passed to the theme argument of add_risktable:

fit.mh.male %>%
  ggcuminc() +
  add_risktable(
    risktable_stats = "n.risk",
    stats_label = list(n.risk = "    No. at Risk"), 
    size = 3,
    theme = list(theme_risktable_default(),
                 theme(plot.title.position = "plot",
                       axis.text.y.left = element_text(hjust = 0,
                            margin = margin(0, 20, 0, 0))))
    ) +
  add_confidence_interval() +
  scale_ggsurvfit() +
  labs(title = "FTMH male",
       x = "Time since surgery")+
  theme(axis.test.y = element_text(hjust = 1)) +
  coord_cartesian(xlim = c(0, 10), 
                  ylim = c(0, 0.04)) + 
  scale_color_jama() +
  scale_fill_jama() +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(color = guide_legend(nrow = 1))


Data used

Note that we don't have your dataset, so I had to create one with similar characteristics and the same variable names. Here is the data I used for the above plot:

set.seed(1)

timesplit.mh.m <- data.frame(Exposure = sample(c("Cataract", "Virectomy"), 
                                               300000, TRUE, prob = c(20, 0.1)))

timesplit.mh.m$status <- rbinom(300000, size = 1, 
    prob = ifelse(timesplit.mh.m$Exposure == "Cataract", 0.008, 0.02))

timesplit.mh.m$time <- runif(300000, 0, 120)/10

timesplit.mh.m$status <- factor(timesplit.mh.m$status)

fit.mh.male <- cuminc(Surv(time, status) ~ Exposure, data =  timesplit.mh.m)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745626434a4636835.html

相关推荐

  • PackML over OPC UA

    在当今数字化转型的浪潮中,制造业正面临着前所未有的挑战与机遇。如何实现设备之间的高效通信与集成,成为提升生产效率、降低成本的关键。OPC UA(OPC Unified Architecture)与PackML(Packaging Machi

    1小时前
    00
  • 万字图解 Java 并发框架:ForkJoin、CountDownLatch、Semaphore、CyclicBarrier

    本文图多,内容硬核,建议收藏。在第一章节《1.6w 字图解 Java 并发:多线程挑战、线程状态和通信、死锁;AQS、ReentrantLock、Condition 使用和原理》,我们开启了 Java 高并发系列的学习,透彻理解 Java

    1小时前
    00
  • 10个 DeepSeek 神级提示词,建议收藏!

    在当下人工智能飞速发展的时代,DeepSeek 作为一款功能强大的 AI 工具,能够帮助我们实现各种创意和需求。然而,要充分发挥它的潜力,掌握一些巧妙的提示词至关重要。今天,就为大家精心整理了 15 个 DeepSeek 神级提示词,涵盖多

    1小时前
    00
  • 非nvidia卡torchvision报错修复: operator torchvision::nms does not exist

    在Ascend 910b上安装vllm, 会自动把torchaudio和torchvision安装上去.安装前代码语言:shell复制pip list | grep torchtorch

    59分钟前
    00
  • 长读长测序揭示结直肠癌异常可变剪接图谱与新型治疗靶点

    徐州医科大学肿瘤研究所董东郑骏年教授团队在Genome Medicine杂志发表题为“Long-read sequencing reveals the landscape of aberrant alternative splicing

    54分钟前
    00
  • Prometheus配置docker采集器

    Prometheus 配置 Docker 采集器Prometheus 是一个开源的监控系统和时间序列数据库,广泛用于容器化环境中。通过监控 Docker 容器,用户可以实时获取服务性能、资源使用情况等信息。本文将介绍如何为 Docker 容

    48分钟前
    00
  • 开源在线考试系统

    看到调问已经开始扩展在线考试的场景,试了一下,发现在线考试的基本能力都已经支持了。主要是考试中的各种计分功能,包括对每道题的选项设置分值计算、考试时间限制等,和官方了解了一下,考试中的其他各项能力也在逐步完善,有需求可以随时

    45分钟前
    00
  • MongoDB “升级项目” 大型连续剧(2)

    上期写的是非必要不升级,想到这个事情,有一些事情的仔细琢磨琢磨,为什么数据库升级的事情在很多公司都是一个困扰,从一个技术人的观点,升级是一件好事,功能提升了,性能提升了,开发效率和一些数据库使用的痛点也被解决了,为什么就不愿意升级呢?如果只

    38分钟前
    00
  • UCB的硅光MEMS OCS控制技术

    昨天写的旭创与nEye合作了一个64端口硅光OCS一、光电路交换技术概述(一)电交换与分组交换电路交换的概念源于早期的电话交换机,通过物理连接实现设备间的通信,就像早期打电话时,接线员手动连接线路一样。而分组交换则是

    32分钟前
    00
  • 推荐一个轻量级的监控平台并且支持移动端

    简介XUGOU 是基于Cloudflare构建的轻量化监控平台,专精于系统资源监控与可视化状态页面服务。该平台提供英文简体中文双语支持,满足全球化部署需求。面向开发者及中小团队,项目致力于提供高可用性的监控解决方案。核心功能与实现平台功能

    30分钟前
    00
  • 【Docker项目实战】使用Docker部署IT工具箱Team·IDE

    一、Team·IDE介绍1.1 Team·IDE简介Team IDE 是一款集成多种数据库(如 MySQL、Oracle、金仓、达梦、神通等)与分布式系统组件(如 Redis、Zookeeper、Kafka、Elasticsearch)管理

    27分钟前
    00
  • 重装系统只影响C盘吗?深入解析系统重装的全过程

    重装系统只影响C盘吗?深入解析系统重装的全过程 在计算机的日常使用中,重装系统是一个常见的操作,尤其是在系统出现故障、感染病毒或需要优化系统性能时。然而,许多用户对于重装系统的具体过程和影响存在误解,认为重装系统仅仅是对C盘进行清空和重置

    27分钟前
    10
  • maxwell遇到的一则问题

    结论和原因maxwell的元数据库里面没有存储全部的schema数据(就是少数据了),导致相关表的DDL校验失败。PS:我这里maxwell的作用只是采集库表修改情况的统计粗粒度指标,因为之前maxwell在运行报错的时候,直接修改了pos

    22分钟前
    00
  • Windows Server20192022 Evaluation评估版未激活导致关机问题

    摘要&#xff1a;在安装Windows Server 20192022后&#xff0c;会出现系统版本为 Evaluation 评估版情况&#xff0c;如提示Windows许可证已到期&#xff0c;就

    20分钟前
    00
  • 人工智能与ai有什么区别

    一、引言:概念之辨的必要性在科技浪潮席卷全球的当下,人工智能(Artificial Intelligence,简称AI)已成为人们耳熟能详的词汇。然而,当我们深入探讨时,会发现“人工智能”与“AI”这两个表述在语义和使用场景上存在微妙差异。

    20分钟前
    00
  • Windows系统密钥检测工具PIDKey 2.1中文版

    Windows系统密钥检测工具PIDKey 2.1中文版 【下载地址】Windows系统密钥检测工具PIDKey2.1中文版 Windows系统密钥检测工具PIDKey 2.1中文版是一款功能强大的工具&#xff0c;专为管理Win

    14分钟前
    00
  • 雨晨 26200.5516 Windows 11 IoT 企业版 LTSC 2024 轻装版

    简述&#xff1a;以下为YCDISM (雨晨作品自2025年03月25日起通用介绍&#xff0c;若无重大更改不再额外敖述) 全程由最新YCDISM2025脱机装载26100.1742_zh-cn_windows_11_

    10分钟前
    00
  • ​2025 轻松部署 Odoo 18 社区版

    随着 Odoo 18 社区版的发布,越来越多的企业希望借助这款开源 ERP 系统实现数字化转型。本文将深入解析传统部署方式的底层逻辑,并揭示如何通过自动化工具实现零门槛快速部署。一、手工部署 Odoo 18 技术全解 Docker 环境搭建

    10分钟前
    00
  • win11家庭版改为专业版

    找到“我的电脑”--“设置”--“系统”--“激活”--“更改密钥” 输入密钥“G49HN-9YQCT-684C3-R7T3F-3DBQB 即可成功。

    18秒前
    00
  • VoidZero 的野心,开发者的福音!

    前言昨天分享了尤雨溪公司 VoidZero 最新的产品 TSDown,我相信肯定有同学和我一样好奇,尤雨溪为什么要推出这么多工具,来增加大家的学习压力!今天我们从整体上分析下,这些产品的功能和目的!正文VoidZero 是尤雨溪于 2020

    16秒前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信