Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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 Plotly ggplot生存曲线如何更改图例文本_R_Plotly_Survival Analysis - Fatal编程技术网

R Plotly ggplot生存曲线如何更改图例文本

R Plotly ggplot生存曲线如何更改图例文本,r,plotly,survival-analysis,R,Plotly,Survival Analysis,我正在使用plotly使我的生存曲线具有交互性。除了图例以以下方式显示每个地层的名称(项目名称,1)外,所有工作正常 我想去掉括号和“1”。通常,当我在ggplot中绘制图形时,它只显示:item_name 我的代码是: km_curve <- ggsurvplot(fit, data = dataset, censor = FALSE, conf.int = TRUE,

我正在使用plotly使我的生存曲线具有交互性。除了图例以以下方式显示每个地层的名称(项目名称,1)外,所有工作正常

我想去掉括号和“1”。通常,当我在ggplot中绘制图形时,它只显示:item_name

我的代码是:

km_curve <- ggsurvplot(fit, 
                   data = dataset, 
                   censor = FALSE,
                   conf.int = TRUE, 
                   risk.table = TRUE,
                   xlab = "Time since Hospital Discharge (years)",  
                   ylab = "Proportion of patients alive", 
                   palette = c("red","orange","yellow","green","blue","brown","pink","black"),
                   legend.title = "Diagnosis",
                   legend.labs = c("Cardiac (Non-surgical)","Cardiac (Surgical)","Gastrointestinal","Neurological","Other","Respiratory","Sepsis","Trauma"))

curve <- km_curve$plot + scale_y_continuous(breaks = seq(0, 1, .25), labels = scales::percent) + 
scale_x_continuous( breaks = seq(0,10,1), expand = c(0, 0))
p <- curve + theme(legend.title = element_text(size = 8), legend.text = element_text(size = 
8),legend.position = "bottom") + coord_cartesian(xlim = c(0,10))
g <- ggplotly(p)
g

km_曲线问题与中相同

类似的解决方案应适用于您的情况:


p之后将其添加到您的代码中。请使用函数
dput
提供虚拟数据,并为上述代码绘制KM生存曲线图。我猜数据集中的组定义为时尚(项目名称,1)?尝试重命名它们并重新绘制。例如,变量的名称就像“男性”或“女性”。没有号码。不幸的是,我不能保存数据,因为它是高度敏感的,而且我对虚拟数据不太满意。只是不确定是否有人知道一种手动修改传奇的方法。非常感谢,这是一个完美的解决方案!