You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用ggsurvplot保存指定尺寸与分辨率的JPEG格式输出?

Hi Tariq, nice question! There are two simple, reliable ways to save your ggsurvplot output as a JPEG with your exact specifications (2.2 inches height, 3.3 inches width, 1000 DPI). Let me break them down for you:

This is the standard, ggplot-friendly way to save plots, and it works seamlessly with ggsurvplot since it returns a ggplot-compatible object.

First, assume you've already created your survival plot object like this:

# Example code to generate your ggsurvplot object
library(survival)
library(survminer)

fit <- survfit(Surv(time, status) ~ sex, data = lung)
gg_plot <- ggsurvplot(fit, data = lung)

Then use ggsave() with your desired parameters:

ggsave(
  filename = "survival_curve.jpg",  # Name your output file
  plot = gg_plot,                   # Pass your ggsurvplot object
  width = 3.3,                      # Width in inches
  height = 2.2,                     # Height in inches
  units = "in",                     # Specify units as inches
  dpi = 1000                        # Set resolution to 1000 DPI
)

Method 2: Use R's Base Graphics Device

If you prefer using R's base plotting utilities, you can manually open a JPEG device, print your plot, then close the device:

# Open the JPEG device with your parameters
jpeg(
  filename = "survival_curve.jpg",
  width = 3.3,
  height = 2.2,
  units = "in",
  res = 1000
)

# Print your ggsurvplot object
print(gg_plot)

# Close the device to finalize the file
dev.off()

A quick note: ggsurvplot itself doesn't have built-in arguments to set save dimensions/resolution directly—since it generates a ggplot-compatible object, we rely on dedicated saving functions like ggsave or base devices to handle those details. Either method above will get you exactly the output you want!

内容的提问来源于stack exchange,提问作者Tariq Nisar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:58:04