我正在嘗試在許多不同的站點創建一個隨時間推移的生存圖。
我有一個相當簡單的資料框如下
我使用以下代碼制作情節:
my_df <- data.frame(x = Survival$time, y = Survival$`% survival`, group = Survival$Site)
ggplot(my_df, aes(x = Survival$time, y = Survival$`% survival`,colour=as.factor("Site")))
geom_point(aes(colour = group, group=1)) # Points and color by group
geom_path(aes(colour=group, group=1), na.value="blank")
scale_color_discrete("Site", na.value=NA) # Change legend title
xlab("Time in Months") # X-axis label
ylab("Percent Survival") # Y-axis label
theme(axis.line = element_line(colour = "black", # Changes the default theme
size = 0.24))
但是由于某種原因,似乎有一條額外的綠線和一條額外的灰線
只是想知道為什么會這樣以及解決此問題的最佳方法是什么
uj5u.com熱心網友回復:
這是一種情況,評論中@Rui Barradas 的所有建議都已實施,并進行了一些其他調整:
library(tidyverse)
my_df %>%
transmute(time = parse_number(X),
survival = y, group = group) %>%
ggplot(aes(x = time, y = survival, colour=factor(group), group=group))
geom_point()
geom_path(size = 1)
scale_color_discrete("group", na.value=NA) # Change legend title
labs(title = "Survival", x = "Time in Months", y = "Percent Survival")
scale_fill_brewer(palette = "Set1")
theme_minimal(base_size = 16)
theme(axis.line = element_line(colour = "black", size = 0.24),
aspect.ratio=4/5)
資料:
structure(list(X = c("0 Months", "2 Months", "4 Months", "6 Months",
"0 Months", "2 Months", "4 Months", "6 Months", "0 Months", "2 Months",
"4 Months", "6 Months", "0 Months", "2 Months", "4 Months", "6 Months"
), y = c(100, 56.45161, 35.48387, 24.19355, 100, 80.76923, 61.53846,
34.61538, 100, 53.06122, 44.89796, 24.4898, 100, 60, 48.57143,
40), group = c("a", "a", "a", "a", "b", "b", "b", "b", "c", "c",
"c", "c", "d", "d", "d", "d")), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491043.html