我想在我的情节中添加一个图例。我一直在努力解决的问题是我无法在图例中显示平均线。相反,我有一个基于类型的线点。我想在图例中得到的是 WT/SHC 的点和相同颜色的平均 WT/SHC 的线。那可能吗?
这是我的数据:
structure(list(vmr_temp = c(0.000651505232465427, 0.0053517614358332,
0.0146827882122448, 0.00635539145671089, 0.0343575014942268,
0.36174893678659, 0.0778899883350459, 0.289848135670948, 0.209959339680751,
0.00405913025062444, 0.0145486338811137, 0.00400672957234268,
0.0343676930196838, 0.105470036120101, 1.36478599015949, 0.00271301387141199,
0.0146894961514807, 0.00662479099801861, 0.00633206013278967,
0.0826430886815124, 0.000236124989922332, 0.000540625939805667,
0.00346901600194693, 0.00494484509687755, 0.0109781756539075,
0.00106492834562357, 0.00279831192505938, 0.000463409848285264,
0.000652145384164669, 0.0336332381486342, 0.343360081948801,
0.166577300901611, 0.357270077835276, 0.26380987699571, 0.00302256823040492,
0.00104296967581199, 0.0120476175691888, 0.0292940823835766,
0.0553962706206964, 0.519685248761818, 0.000817020240142651,
0.00093258668979934, 0.000105471759211712, 0.0170464412705115,
0.0481955561250614, 0.00107243214969894, 0.0172713764321815,
0.0722947706678404, 0.00580093907914223, 0.000263741516896747
), lipids = structure(c(6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 1L, 2L,
3L, 4L, 5L, 6L, 8L, 7L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
18L, 17L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 1L, 2L, 5L, 3L,
4L), .Label = c("CL [66:0]", "CL [70:2]", "CL [70:4]", "CL [72:4]",
"CL [74:2]", "PC [32:1]", "PC [32:2]", "PC [34:1]", "PC [34:2]",
"PC [34:3]", "PC [34:4]", "PC [36:2]", "PC [36:3]", "PC [36:4]",
"PE [32:1]", "PE [34:1]", "PE [34:2]", "PE [36:1]", "PE [36:2]",
"PE [36:3]", "PG [32:1]", "PG [34:1]", "PG [34:2]", "PG [36:2]",
"PG [36:3]"), class = "factor"), type = structure(c(2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("SHC",
"WT"), class = "factor"), mean_temp = c(0.106450191953034, 0.106450191953034,
0.106450191953034, 0.106450191953034, 0.106450191953034, 0.106450191953034,
0.106450191953034, 0.106450191953034, 0.106450191953034, 0.106450191953034,
0.106450191953034, 0.106450191953034, 0.106450191953034, 0.106450191953034,
0.106450191953034, 0.106450191953034, 0.106450191953034, 0.106450191953034,
0.106450191953034, 0.106450191953034, 0.106450191953034, 0.106450191953034,
0.106450191953034, 0.106450191953034, 0.106450191953034, 0.0781567385802059,
0.0781567385802059, 0.0781567385802059, 0.0781567385802059, 0.0781567385802059,
0.0781567385802059, 0.0781567385802059, 0.0781567385802059, 0.0781567385802059,
0.0781567385802059, 0.0781567385802059, 0.0781567385802059, 0.0781567385802059,
0.0781567385802059, 0.0781567385802059, 0.0781567385802059, 0.0781567385802059,
0.0781567385802059, 0.0781567385802059, 0.0781567385802059, 0.0781567385802059,
0.0781567385802059, 0.0781567385802059, 0.0781567385802059, 0.0781567385802059
)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA,
-50L), vars = "type", labels = structure(list(type = structure(1:2, .Label = c("SHC",
"WT"), class = "factor")), class = "data.frame", row.names = c(NA,
-2L), vars = "type", labels = structure(list(type = structure(1:2, .Label = c("SHC",
"WT"), class = "factor")), class = "data.frame", row.names = c(NA,
-2L), vars = "type", labels = structure(list(type = structure(1:2, .Label = c("SHC",
"WT"), class = "factor")), row.names = c(NA, -2L), class = "data.frame", vars = "type", drop = TRUE, .Names = "type"), indices = list(
25:49, 0:24), drop = TRUE, group_sizes = c(25L, 25L), biggest_group_size = 25L, .Names = "type"), indices = list(
25:49, 0:24), drop = TRUE, group_sizes = c(25L, 25L), biggest_group_size = 25L, .Names = "type"), indices = list(
25:49, 0:24), drop = TRUE, group_sizes = c(25L, 25L), biggest_group_size = 25L, .Names = c("vmr_temp",
"lipids", "type", "mean_temp"))
到目前为止,这就是我所拥有的:
ggplot(test, aes(x = lipids, y= vmr_temp, col= type)) +
geom_point() +
#facet_grid(type ~ .) +
geom_hline(aes(yintercept = mean_temp, group = type,color = factor(type)),show.legend = TRUE) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))