我的数据框是
df <- structure(list(pred_D_class = structure(1:16, .Label = c("2",
"6", "10", "14", "18", "22", "26", "30", "34", "38", "42", "46",
"50", "54", "58", "62", "66"), class = "factor"), sr = c(0.809651537358495,
0.117375642771934, -0.363261042177462, -0.108072060684085, 0.317179663964105,
0.580775326984562, -0.264034203498261, -1.33324816316546, -1.62553076157225,
-1.41389979866552, 1.88153232792938, 5.27111236575782, 6.54991048921335,
8.45749771079771, 6.59078999361768, 16.5363599853556), sr1 = c(-0.461973610529103,
-0.632872471230115, -0.615633624705446, 0.191948419914372, 0.724674733712783,
0.856251476967346, -0.255899968913292, -2.60345961297358, -4.17467513135888,
-5.40431493394634, -4.50433525555663, -3.77830406394879, -6.17234432719018,
-6.82309808877181, -13.2855824994648, -7.88630469512728), sr2 = c(1.5034529269785,
1.50797890743077, 0.522711463953773, 0.0884734945633313, -0.0740798054484882,
-0.0134157046284108, -1.0261643625092, -2.22477319635843, -2.2938676440796,
-2.48543981495454, -1.89315257576394, -2.35142885487948, -2.57245688973948,
-1.9149000167909, -4.97513391133261, 4.42059763647021), co = c(25L,
1580L, 5579L, 10895L, 9520L, 5091L, 3084L, 1681L, 1055L, 609L,
270L, 133L, 61L, 19L, 1L, 1L)), .Names = c("pred_D_class", "sr",
"sr1", "sr2", "co"), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"), drop = TRUE)
对于这个data.frame
,我会关注ggplot
library(reshape2)
df1 <- subset(melt(df), variable != "co")
library(ggplot2)
ggplot(aes(x = pred_D_class, y = value, group = variable, color = variable), data = rez1) + geom_point() + geom_line()
我想现在添加代表co
中的列df data.frame
的标签,并且对于所有组sr, sr1, sr2
都是通用的。此值可以放在y = 15
中,也可以放在红线后面。
到目前为止,我尝试了与geom_text, geom_label
和annotate
的不同组合,但没有成功。