2017-05-17 20 views
1

Survminerは素晴らしいプロットを生成しますが、通常のggplotコマンドで結果をさらに変更する方法はありますか?survminer + scale_x_continuousエラー

hereと記載されているように、私がしようとしているのは、y軸を原点で始めることです。定期ggplotについては が、これは完璧に動作しますが、私はそれがsurvminerで動作させることができない:これはエラー

"Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale."

と追加のエラーを生成します

library(survival) 
library(survminer) 

df<-genfan 
df$treat<-sample(c(0,1),nrow(df),replace=TRUE) 


fit <- survfit(Surv(hours, status) ~ treat, 
       data = df) 

p<-ggsurvplot(fit, data = df, risk.table = TRUE,,ncensor.plot=FALSE,tables.theme = theme_cleantable(), 
       ggtheme = theme_survminer(font.legend=c(12,"bold","black"))) 


p%+%scale_x_continuous(expand=c(0,0))%+%scale_y_continuous(expand=c(0,0)) 

"Error: Discrete value supplied to continuous scale"

これを回避する方法はありますか?

+0

'genfan'はどのように入手できますか?最初のメッセージはエラーではなく警告です。 2番目のメッセージは 'リスクテーブル= TRUE'と関係しています。これは連続したy軸の代わりに離散したy軸を持つ2番目のプロットを作成しているように見えます。 – aosmith

+0

@aosmith 'genfan'は' survival'パッケージで利用可能なデータセットです。 – KoenV

答えて

2

問題の可能な解決策は、expand=c(0,0)を適切な場所に挿入してggsurvplotggrisktableを変更することです。
このlinkに私の提案を見つけることができます。
「ダウンロード」をクリックし、a_modified_ggsurvplot.txtというファイルを作業ディレクトリに保存します。
は、その後、次のコードを実行します。ここでは

library(survival) 
library(survminer) 

df <- genfan 
df$treat <- sample(c(0,1),nrow(df),replace=TRUE) 
fit <- survfit(Surv(hours, status) ~ treat, data = df) 

source("a_modified_ggsurvplot.txt") 
p <- myggsurvplot(fit, data = df, risk.table = TRUE, 
    ncensor.plot=FALSE,tables.theme = theme_cleantable(), 
    ggtheme = theme_survminer(font.legend=c(12,"bold","black"))) 
print(p) 

はプロットである: enter image description here

それはあなたを助けることができる願っています。

関連する問題