¡Hola! Espero que estén muy bien.
Le he dado muchas vueltas a este asunto pero ggplot lleva ganada la batalla. Les consulto. Tengo un conjunto de datos longitudinales y se hicieron varios ajustes sobre ellos. Ahora, intento colocar las predicciones sobre el mismo gráfico con el código adjunto. Mi problema exacto es que quisiera que la leyenda, además del tipo de línea, pudiera mostrar el color de la línea. En este momento, solo los individuos tienen líneas grises continuas, sin embargo la leyenda solo muestra la línea continua, y negra. ¿Alguien podría ayudarme? ¡Gracias! -- «Pídeles sus títulos a los que te persiguen, pregúntales cuándo nacieron, diles que te demuestren su existencia.» Rafael Cadenas
parametros<-structure(list(X = 1:51, X.1 = c(93.6443045794884, 0.274514923404001, -0.618328826511992, 6.35004789645277, 80.4486680704678, 0.398671210849383, -0.36311742015548, 1.03735833192979, 123.433079354653, 0.0102818971461322, 0.0737926758635394, 0.667956051190706, 0.166023046221436, 0.169835680441718, 92.8727273392054, 0.280548440675895, -0.591788496784862, 6.34069803543858, 0.00396918686734812, 0.003873777667181, 0.00397871442819185, 8.62002235763456e-05, 0.000177982071249404, -7.20746737162845e-05, 83.6179497099678, 0.37456999758485, -0.395741042334919, 1.35275234352414, 9.19666589730974, 0.049465436765756, 0.262280809304406, 90.4949487031123, 0.309798683863988, -0.455118957698306, 4.59410797144556, 6.70214183242127, 2.55241318343321, 0.0040969271690877, 0.00406057805801237, 0.00408729052989319, -0.0001337437288817, -9.02974739023956e-05, -4.79605394640869e-05, 84.1324991529296, 0.371924990227874, -0.394364833252805, 12.2942829860544, 15.1762245140945, 9.39329446699581, 15.2777604868252, 1.12559789523233 ), X2.5. = c(89.8075680676307, 0.24062495144807, -0.77721816380053, 6.10328321127024, 82.0970864037386, 0.41628213216484, -0.316459851584057, 1.10925276972414, 151.676569972767, 0.0136445644723838, 0.0964128077066584, 0.566110617222703, 0.0719498743654596, 0.288082253061202, 88.7480021052549, 0.248299724724991, -0.738083589646706, 6.13608196789711, 0.0033131765251182, 0.00331992605912848, 0.00330510660938651, -0.000385787681769791, -0.000279920354928013, -0.000648710689208116, 82.1887422364474, 0.361429662565472, -0.444308809159175, 1.26215061383911, 8.34267614185542, 0.0373843251863912, 0.231315025808771, 88.4278512805936, 0.28043065708031, -0.576980216992324, 3.72759905121779, 2.51202639984708, 2.50514689364638, 0.00352687109447984, 0.00343525744154969, 0.00338207649947237, -0.000660750333682392, -0.000468516920705751, -0.000454316005673436, 82.6462425607854, 0.359068069451452, -0.441167465031998, 8.62796498220036, 10.1227010680911, 5.12805200272888, 9.26381073259622, 1.01759087592246 ), X97.5. = c(98.3877041960296, 0.309426923468285, -0.477640818649688, 6.61776093280683, 83.7455047370094, 0.433893053480296, -0.269802283012633, 1.18612987361049, 186.382629348511, 0.0181069832731281, 0.12596683046256, 0.447134504827384, 0.0136480105954702, 0.411703462075963, 97.0714933511228, 0.3231018418536, -0.440032765543431, 6.5910793206374, 0.00458902518252994, 0.00459529042640684, 0.00459033307804952, 0.000433596593495416, 0.000469433582168282, 0.000280674306287311, 84.9503686450073, 0.388274472592534, -0.348087133287464, 1.45030802655994, 10.2002714211677, 0.0609950356940555, 0.299171819309348, 93.548966629373, 0.333696770103566, -0.363375587398017, 5.0879499410823, 9.76329673573814, 2.7431077428306, 0.00474466476593635, 0.0046929951241291, 0.00478980004233669, 0.000449783679712311, 0.000413896440866447, 0.000443348858707374, 85.4751963528418, 0.384064677811932, -0.348277751176412, 17.4449169639356, 22.4575183191046, 16.3379448906165, 24.2774760534726, 1.23218199233448 )), .Names = c("X", "X.1", "X2.5.", "X97.5."), row.names = c(NA, -51L), class = "data.frame") dd<-structure(list(x = c(1L, 2L, 3L, 4L, 5L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 4L, 5L, 1L, 2L, 3L, 5L, 3L, 4L, 5L, 4L, 1L, 2L, 3L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 4L, 1L, 3L, 4L), y = c(28.032936, 47.78408, 59.070448, 66.124428, 71.767612, 59.6954225, 66.54971, 73.4039975, 78.8874275, 30.3693767567568, 47.0061689189189, 61.0834545945946, 66.2024675675676, 71.3214805405405, 76.4404935135135, 31.2924053333333, 44.719304, 55.4608229333333, 66.2023418666667, 74.2584810666667, 79.6292405333333, 82.3146202666667, 32.530764556962, 44.8980734177215, 57.265382278481, 65.9224984810127, 70.8694220253165, 75.8163455696203, 29.5625964864865, 72.2403994594595, 77.4134664864865, 44.697832238806, 60.9025955223881, 72.6878779104478, 80.0536794029851, 60.0298032876712, 67.7313161643836, 74.1492435616438, 63.8927616901408, 41.4199444444444, 53.4455622222222, 66.9743822222222, 77.4967977777778, 38.719304, 59.4511302857143, 65.929826, 69.8170434285714, 72.4085217142857, 37.7617025, 52.841135, 65.1788525, 72.03314, 77.51657, 80.258285, 43.1916384615385, 56.4426486153846, 63.8043209230769, 68.2213243076923, 74.1106621538461, 78.5276655384615, 64.13333675, 69.36842375, 75.9122825, 79.83859775, 28.9241555882353, 41.6744114705882, 50.5995905882353, 59.5247697058823, 64.6248720588235, 68.4499488235294, 35.0491827272727, 59.6996309090909, 49.6580332307692, 60.3290166153846, 66.9983812307692, 31.5926751282051, 45.6531769230769, 55.8789964102564, 67.3830433333333, 72.4959530769231, 76.3306353846154, 80.1653176923077, 34.9836983098592, 56.3249354929577, 66.995554084507, 73.6646907042254, 77.6661726760563, 32.0665111627907, 51.173811627907, 60.7274618604651, 70.2811120930233, 76.2521434883721, 79.8347623255814, 83.4173811627907, 40.9105569014084, 57.0854988732394, 71.9125290140845, 37.6178008571429, 69.0626582857143, 74.5313291428571), id_ = c(7001091997137, 7001091997137, 7001091997137, 7001091997137, 7001091997137, 7001091997145, 7001091997145, 7001091997145, 7001091997145, 7001091997161, 7001091997161, 7001091997161, 7001091997161, 7001091997161, 7001091997161, 7001091997173, 7001091997173, 7001091997173, 7001091997173, 7001091997173, 7001091997173, 7001091997173, 70010919972, 70010919972, 70010919972, 70010919972, 70010919972, 70010919972, 70010919973, 70010919973, 70010919973, 70010919975, 70010919975, 70010919975, 70010919975, 70010919978, 70010919978, 70010919978, 700109199715, 700109199726, 700109199726, 700109199726, 700109199726, 700109199739, 700109199739, 700109199739, 700109199739, 700109199739, 700109199744, 700109199744, 700109199744, 700109199744, 700109199744, 700109199744, 700109199748, 700109199748, 700109199748, 700109199748, 700109199748, 700109199748, 700109199752, 700109199752, 700109199752, 700109199752, 700109199753, 700109199753, 700109199753, 700109199753, 700109199753, 700109199753, 700109199760, 700109199760, 700109199772, 700109199772, 700109199772, 700109199773, 700109199773, 700109199773, 700109199773, 700109199773, 700109199773, 700109199773, 700109199776, 700109199776, 700109199776, 700109199776, 700109199776, 700109199777, 700109199777, 700109199777, 700109199777, 700109199777, 700109199777, 700109199777, 700109199781, 700109199781, 700109199781, 700109199783, 700109199783, 700109199783)), .Names = c("x", "y", "id_"), row.names = c(NA, 100L), class = "data.frame") library(ggplot2) VB <- function(age, Linf, k, t0) return(Linf*(1-exp(-k*(age-t0)))) ggplot() + geom_line(data = dd, aes(x = x, y = y, group = id_, linetype = 'Inds'), size = .5, colour='gray') + geom_line(data=data.frame(x=c(1:15), y=VB(c(1:15), parametros[1,2], parametros[2,2], parametros[3,2])), aes(x=x,y=y, linetype = 'FFR'), size = 1) + geom_line(data=data.frame(x=c(1:15), y=VB(c(1:15), parametros[5,2], parametros[6,2], parametros[7,2])), aes(x=x,y=y, linetype = 'FRE'), size = 1) + geom_line(data=data.frame(x=c(1:15), y=VB(c(1:15), parametros[15,2], parametros[16,2], parametros[17,2])), aes(x=x,y=y, linetype = 'BNRE I'), size = 1) + geom_line(data=data.frame(x=c(1:15), y=VB(c(1:15), parametros[25,2], parametros[26,2], parametros[27,2])), aes(x=x,y=y, linetype = 'BNRE II'), size = 1) + geom_line(data=data.frame(x=c(1:15), y=VB(c(1:15), parametros[32,2], parametros[33,2], parametros[34,2])), aes(x=x,y=y, linetype = 'BTRE I'), size = 1) + geom_line(data=data.frame(x=c(1:15), y=VB(c(1:15), parametros[44,2], parametros[45,2], parametros[46,2])), aes(x=x,y=y, linetype = 'BTRE II'), size = 1) + xlab('Age') + ylab('Length') + ylim(15,120) + theme_bw() + theme(axis.title.y = element_text(size = rel(2.5)), axis.title.x = element_text(size = rel(2.5)), axis.text=element_text(size=15), legend.text = element_text(size = rel(1.3)), legend.position = c(0.8, 0.2), legend.title = element_blank()) + scale_linetype_manual(name = '', values=c('Inds'='solid','FFR'='dashed','FRE'='dotted','BNRE I'='dotdash', 'BNRE II'='longdash','BTRE I'='twodash','BTRE II'='dashed'), breaks = c('Inds','FFR','FRE','BNRE I','BNRE II','BTRE I', 'BTRE II'))
_______________________________________________ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es