Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R/ggplot中剪切图形?_R_Ggplot2_Graph - Fatal编程技术网

如何在R/ggplot中剪切图形?

如何在R/ggplot中剪切图形?,r,ggplot2,graph,R,Ggplot2,Graph,R 我有以下代码: ggsurvplot(curve.histology, conf.int=TRUE, legend.labs=legend.histology, surv.scale=c("percent"),risk.table=T, ggtheme = theme_bw(), risk.table.fontsize=3.5, xlim=c(0,5), ylim=c(0,1), break.time.by=1) “曲线组织学”中有四个变量。我希望所有四个图形都停止在x=5,就像我的

R

我有以下代码:

ggsurvplot(curve.histology, conf.int=TRUE, 
legend.labs=legend.histology, surv.scale=c("percent"),risk.table=T, 
ggtheme = theme_bw(), risk.table.fontsize=3.5, xlim=c(0,5), 
ylim=c(0,1), break.time.by=1)
“曲线组织学”中有四个变量。我希望所有四个图形都停止在x=5,就像我的x轴一样。有人能帮忙吗


curve.orbiologyIIUC,在
coord\u cartesian()
上设置
xlim
expand=0L
可能会有所帮助(只要按
theme()
排列边距即可)。但是,我认为您应该向survminer包的存储库提交一个问题,因为在ggsurvplot中编辑ggplot对象有点痛苦

reprex::reprex_info()
#> Created by the reprex package v0.1.1.9000 on 2017-11-12

library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
library(survival)

fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung, xlim = c(0, 900), expand = FALSE)

p$plot <- p$plot +
  coord_cartesian(xlim = c(0, 900), expand = FALSE) +
  theme(plot.margin = margin(5.5, 20, 5.5, 5.5))
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.
p
reprex::reprex_info()
#>由2017年11月12日的reprex包v0.1.1.9000创建
图书馆(survminer)
#>加载所需包:ggplot2
#>加载所需包:ggpubr
#>装载所需包装:magrittr
图书馆(生存)

你能给我一个曲线样本吗?很难知道没有这些数据会发生什么…我在正文中添加了一个图像
reprex::reprex_info()
#> Created by the reprex package v0.1.1.9000 on 2017-11-12

library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
library(survival)

fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung, xlim = c(0, 900), expand = FALSE)

p$plot <- p$plot +
  coord_cartesian(xlim = c(0, 900), expand = FALSE) +
  theme(plot.margin = margin(5.5, 20, 5.5, 5.5))
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.
p