[英]Labelling the legend in ggplot2 and ggfortify in R
我繪制了一個圖形並想自定義該圖的圖例。 我將感謝所有幫助。 謝謝!
library("survival")
library("ggplot2")
library("ggfortify")
data(lung)
lung$SurvObj <- with(lung, Surv(time, status == 2))
km.by.sex <- survfit(SurvObj ~ sex, data = lung, conf.type = "log-log")
gender.plot <- autoplot(km.by.sex)
gender.plot <- gender.plot +
ggtitle("Gender based Survival (1=male, 2=female)") +
labs(x = "Time", y = "Survival Probability")
print(gender.plot)
我在自定義 ggfortify 情節時遇到了類似的問題 - 我不確定這個問題在問什么,但我假設您想從ggfortify
的autoplot
自定義圖例。 為了快速回答這個問題 - autoplot
可以使用典型的ggplot
函數進行自定義操作,因為它是一個ggplot
對象。 這應該是修改圖例的方法, autoplot
沒有自己的庫。 有關更多信息,請參閱此已關閉問題。
我使用此處找到的生存分析示例對您的問題進行了輕微編輯,以包含可重現的代碼。 自定義繪圖的示例(重命名圖例和顏色標簽):
gender.plot <- autoplot(km.by.sex)
gender.plot <- gender.plot +
ggtitle("Gender based Survival") +
labs(x = "Time", y = "Survival Probability") +
guides(fill=FALSE) +
labs(colour = "Gender") +
scale_color_manual(labels = c("Male", "Female"), values = c(1, 2))
print(gender.plot)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.