R 无法使用ggplot放置图例

R 无法使用ggplot放置图例,r,ggplot2,time-series,R,Ggplot2,Time Series,我试图用拟合曲线(xm1a、xm1b、xm1c)和趋势线(xm21a、xm21b、xm21c)绘制3个时间序列数据(int1a、int1b、int2c)。我得到了这个图(见附件),但是,我无法在这个图的顶部加上一个图例 代码 fn_fr1 = data.frame(xs, int1a, xm1a, xm21a, int1b, xm1b, xm21b, int1c, xm1c, xm21c) labs = c("2007","2008","2009","2010","2011","2012

我试图用拟合曲线(xm1a、xm1b、xm1c)和趋势线(xm21a、xm21b、xm21c)绘制3个时间序列数据(int1a、int1b、int2c)。我得到了这个图(见附件),但是,我无法在这个图的顶部加上一个图例

代码

fn_fr1   = data.frame(xs, int1a, xm1a, xm21a,  int1b, xm1b, xm21b, int1c, xm1c, xm21c)

labs = c("2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017")

 ggplot(data=fn_fr1, aes(xs, y = value, color = variable)) + 
 theme_set(theme_bw()) +
# ------------------ NC --------------   
 geom_line(aes(y = xm1a), colour="black") +
 geom_point(aes(y = int1a), shape =21, colour = "Black", fill="white") + 
 geom_line(aes(y = xm21a),colour='black', linetype="dashed", size=1.25) +

 ylim(200,max(fn_fr1$int1a)) +
 theme(plot.title=element_text(vjust=0.75, hjust=1.0)) +
 scale_x_continuous(name="year", breaks=seq(0,10,1), labels=labs) +
 ylab("CO (ppb)") +
# ------------------ YS --------------  
 geom_line(aes(y = xm1b), colour="Red") +
 geom_point(aes(y = int1b), shape =25, colour = "Red", fill="white") + 
 geom_line(aes(y = xm21b),colour='Red', linetype="dashed", size=1.25) +
# ------------------ SK --------------  
 geom_line(aes(y = xm1c), colour="blue") +
 geom_point(aes(y = int1c), shape =22, colour = "Blue", fill="white") + 
 geom_line(aes(y = xm21c),colour='blue', linetype="dashed", size=1.25) + 

 theme(legend.position = "top", legend.box = "horizontal") +
# scale_fill_identity(name = 'Fitting',values = c(int1a='point', xm1a='solid',xm21a='dashed'), labels = c('Data','Curve','Trend')) +
 scale_colour_manual(name = 'Regions',values = c(int1a='black', int1a='red', int1c='blue'),   labels = c('NC','YS','SK'))
绘图

数据

dput(fn_fr1) 结构(列表)(xs=c(0.0833333,0.1666667, 0.25, 0.333333333333333, 0.416666666666667, 0.5, 0.583333333333333, 0.666666666666667, 0.75, 0.833333333333333, 0.916666666666667, 1, 1.08333333333333, 1.16666666666667, 1.25, 1.33333333333333, 1.41666666666667, 1.5, 1.58333333333333, 1.66666666666667, 1.75, 1.83333333333333, 1.91666666666667, 2, 2.08333333333333, 2.16666666666667, 2.25, 2.33333333333333, 2.41666666666667, 2.5, 2.58333333333333, 2.66666666666667, 2.75, 2.83333333333333, 2.91666666666667, 3, 3.08333333333333, 3.16666666666667, 3.25, 3.33333333333333, 3.41666666666667, 3.5, 3.58333333333333, 3.66666666666667, 3.75, 3.83333333333333, 3.91666666666667, 4, 4.08333333333333, 4.16666666666667, 4.25, 4.33333333333333, 4.41666666666667, 4.5, 4.58333333333333, 4.66666666666667, 4.75, 4.83333333333333, 4.91666666666667, 5, 5.08333333333333, 5.16666666666667, 5.25, 5.33333333333333, 5.41666666666667, 5.5, 5.58333333333333, 5.66666666666667, 5.75, 5.83333333333333, 5.91666666666667, 6, 6.08333333333333, 6.16666666666667, 6.25, 6.33333333333333, 6.41666666666667, 6.5, 6.58333333333333, 6.66666666666667, 6.75, 6.83333333333333, 6.91666666666667, 7, 7.08333333333333, 7.16666666666667, 7.25, 7.33333333333333, 7.41666666666667, 7.5, 7.58333333333333, 7.66666666666667, 7.75, 7.83333333333333, 7.91666666666667, 8, 8.08333333333333, 8.16666666666667, 8.25, 8.33333333333333, 8.41666666666667, 8.5, 8.58333333333333, 8.66666666666667, 8.75, 8.83333333333333, 8.91666666666667, 9, 9.08333333333333, 9.16666666666667, 9.25, 9.33333333333333, 9.41666666666667, 9.5, 9.58333333333333, 9.66666666666667, 9.75,9.83333,9.916667,10),int1a=c(412.618, 417.365, 426.564, 436.479, 409.058, 420.529, 357.221, 337.316, 396.084, 328.479, 402.208, 403.981, 383.41, 419.888, 406.845, 418.03, 421.147, 403.514, 347.393, 309.471, 326.381, 304.262, 333.966, 381.643, 392.275, 366.146, 383.912, 386.86, 376.235, 378.791, 346.391, 337.8743, 329.3577, 320.841, 332.464, 394.367, 400.604, 449.253, 415.621, 428.912, 388.973, 415.633, 345.161, 335.088, 337.939, 310.362, 345.306, 385.682, 433.578, 363.128, 403.021, 387.169, 363.308, 369.108, 350.907, 309.599, 318.528, 315.991, 325.17, 393.396, 406.018, 434.134, 386.448, 379.065, 397.774, 406.794, 371.856, 342.974, 344.137, 334.502, 377.724, 399.812, 378.32, 391.701, 371.87, 387.259, 352.933, 341.107, 295.422, 329.295, 311.654, 321.219, 357.065, 366.415, 368.174, 334.571, 385.537, 381.445, 364.511, 365.879, 340.919, 353.402, 312.776, 313.294, 322.474, 385.18, 377.931, 423.021, 343.333, 367.12, 367.017, 347.578, 347.122, 363.955, 330.208, 306.996, 343.601, 389.57, 392.409, 406.115, 382.578, 380.56, 331.648, 339.755, 309.121, 280.077, 324.274, 290.452, 329.763, 383.197 ),xm1a=c(415.167934456542412.5961307209352415.856825012261, 405.089519764465, 401.816536077282, 392.193298133505, 360.329956586584, 349.018817459014, 347.662836030865, 336.017798415484, 362.230854965844, 406.177420046444, 411.224017277482, 408.652213541875, 411.912907833201, 401.145602585406, 397.872618898222, 388.249380954445, 356.386039407524, 345.074900279955, 343.718918851805, 332.073881236424, 358.286937786784, 402.233502867384, 407.280100098422, 404.708296362815, 407.968990654142, 397.201685406346, 393.928701719162, 384.305463775386, 352.442122228464, 341.130983100895, 339.775001672745, 328.129964057364, 354.343020607725, 398.289585688324, 403.336182919363, 400.764379183756, 404.025073475082, 393.257768227286, 389.984784540103, 380.361546596326, 348.498205049404, 337.187065921835, 335.831084493685, 324.186046878304, 350.399103428665, 394.345668509265, 399.392265740303, 396.820462004696, 400.081156296022, 389.313851048226, 386.040867361043, 376.417629417266, 344.554287870345, 333.243148742775, 331.887167314626, 320.242129699245, 346.455186249605, 390.401751330205, 395.448348561243, 392.876544825636, 396.137239116962, 385.369933869167, 382.096950181983, 372.473712238207, 340.610370691285, 329.299231563716, 327.943250135566, 316.298212520185, 342.511269070546, 386.457834151145, 391.504431382184, 388.932627646576, 392.193321937903, 381.426016690107, 378.153033002924, 368.529795059147, 336.666453512225, 325.355314384656, 323.999332956506, 312.354295341125, 338.567351891486, 382.513916972085, 387.560514203124, 384.988710467517, 388.249404758843, 377.482099511047, 374.209115823864, 364.585877880087, 332.722536333166, 321.411397205596, 320.055415777447, 308.410378162066, 334.623434712426, 378.569999793026, 383.616597024064, 381.044793288457, 384.305487579783, 373.538182331988, 370.265198644804, 360.641960701027, 328.778619154106, 317.467480026537, 316.111498598387, 304.466460983006, 330.679517533366, 374.626082613966, 379.672679845004, 377.100876109397, 380.361570400724, 369.594265152928, 366.321281465744, 356.698043521968, 324.834701975046, 313.523562847477, 312.167581419327, 300.522543803946, 326.735600354306, 370.682165434906),xm21a=c(385.487456012838385.158796247916, 384.830136482994, 384.501476718073, 384.172816953151, 383.84415718823, 383.515497423308, 383.186837658386, 382.858177893465, 382.529518128543, 382.200858363621, 381.8721985987, 381.543538833778, 381.214879068856, 380.886219303935, 380.557559539013, 380.228899774091, 379.90024000917, 379.571580244248, 379.242920479326, 378.914260714405, 378.585600949483, 378.256941184562, 377.92828141964, 377.599621