Muy bueno Carlos. Gracias por compartir El mié., 18 jul. 2018 23:50, Carlos Ortega <c...@qualityexcellence.es> escribió:
> Hola, > > Nos prodigamos poco en la lista en recomendar el uso de "addins", que > permiten ayudar en múltiples cosas con un par de clicks. > Con este puedes mejorar tu gráfico "ggplot" en gran medida (leyendas > incluidas): > > https://github.com/calligross/ggthemeassist > > Saludos, > Carlos Ortega > www.qualityexcellence.es > > El 18 de julio de 2018, 20:29, Sebastián Rangel <sebasran...@gmail.com> > escribió: > > > ¡Gracias! Espectacular. Me ha servido mucho. > > > > El mié., 18 de jul. de 2018 1:15 PM, Víctor Granda García < > > victorgrandagar...@gmail.com> escribió: > > > > > Hola Sebastián. > > > > > > Entiendo que tratas de que aparezca una leyenda con el tipo de curva > > > (l,o,u,i). Si quieres aprovechar las ventajas de ggplot (como las > > leyendas > > > automáticas) normalmente tienes que asignar linetype a una variable, y > > para > > > eso tienes que modificar un poco tus datos. Los has creado en formato > > > "wide" (ancho), donde tienes la columna t y una columna para cada > curva. > > > Pero para lo que quieres hacer en ggplot, necesitas un formato "long" > > > (largo), donde tienes una columna con el tipo de curva (l,o,u,i) otra > > > columna con los valores para cada curva y la columna t, solo que > repetida > > > para cada curva. > > > > > > Con este código puedes cambiar los datos y hacer la gráfica como > quieres: > > > > > > library(ggplot2) > > > > > > t=seq (-4, 4, by=0.01) > > > > > > #### Con b=-2 > > > > > > l=exp(t+2)/(1+(exp(t+2))) > > > > > > ##con b igual a -1 > > > > > > o=exp(t+1)/(1+(exp(t+1))) > > > > > > ### Con b igual a 0.7 > > > > > > i=exp(t-0.7)/(1+(exp(t-0.7))) > > > > > > ### Con b igual a 2 > > > > > > u=exp(t-2)/(1+(exp(t-2))) > > > > > > ####unir los datos > > > b=c(0.3,2,-1,-2) > > > > > > datos <- data.frame( > > > t = t, > > > l = l, > > > o = o, > > > i = i, > > > u = u > > > ) > > > > > > # ahora usamos gather, del paquete tidyr, porque nos permite pasar del > > > formato > > > # "wide" a "long" > > > library(tidyr) > > > # install.packages('tidyr') > > > datos_long <- gather(datos, Curva, Valor, 2:5) > > > datos_long > > > > > > ###Graficos > > > > > > ggplot(datos_long, aes(x = t, y = Valor, linetype = Curva)) + > > > geom_line(color="gray48", size=1.2)+ > > > labs(x = expression(paste(theta)), y="Probabilidad")+ > > > theme(axis.text=element_text(size=14, face="bold"), > > > axis.title=element_text(size=14)) > > > > > > > > > Como ves, datos_long ahora si que permite que asignes linetype a una > > > variable (Curva) y automáticamente te dibuja diferentes tipos de linea > > para > > > cada curva y te coloca una leyenda. > > > > > > Espero que te sirva, un saludo!! > > > > > > On Wed, 18 Jul 2018 at 19:50 Sebastián Rangel <sebasran...@gmail.com> > > > wrote: > > > > > >> Buenas tardes, estoy haciendo una gráfica de múltiples lineas pero no > he > > >> podido generar las legendas. Alguno de ustedes me podría colaborar. > > >> > > >> library(ggplot2) > > >> > > >> #### Con b=-2 > > >> t=seq (-4, 4, by=0.01) > > >> l=exp(t+2)/(1+(exp(t+2))) > > >> > > >> ##con b igual a -1 > > >> > > >> t=seq (-4, 4, by=0.01) > > >> o=exp(t+1)/(1+(exp(t+1))) > > >> > > >> ### Con b igual a 0.7 > > >> > > >> t=seq (-4, 4, by=0.01) > > >> i=exp(t-0.7)/(1+(exp(t-0.7))) > > >> > > >> ### Con b igual a 2 > > >> > > >> t=seq (-4, 4, by=0.01) > > >> u=exp(t-2)/(1+(exp(t-2))) > > >> > > >> ####unir los datos > > >> b=c(0.3,2,-1,-2) > > >> datos=cbind(l,o,i,u) > > >> datos=data.frame(datos) > > >> > > >> ###Graficos > > >> > > >> ggplot( )+ > > >> geom_line(aes(y = i, x=t), color="gray48", size=1.2, > > linetype="dashed") > > >> + > > >> geom_line(aes(y = u, x=t), color = "gray48", > > >> size=1.2,linetype="twodash")+ > > >> geom_line(aes(y = o,x=t), color = "gray48", > > >> size=1.2,linetype="longdash") + > > >> geom_line(aes(y = l,x=t), color="gray48", > size=1.2,linetype="solid")+ > > >> labs(x = expression(paste(theta)), y="Probabilidad")+ > > >> theme(axis.text=element_text(size=14, face="bold"), > > >> axis.title=element_text(size=14)) > > >> > > >> Saludos, > > >> > > >> Sebastián Rangel Quiñonez > > >> > > >> [[alternative HTML version deleted]] > > >> > > >> _______________________________________________ > > >> R-help-es mailing list > > >> R-help-es@r-project.org > > >> https://stat.ethz.ch/mailman/listinfo/r-help-es > > >> > > > -- > > > *Víctor Granda García* > > > Data Technician > > > > > > > > > v.gra...@creaf.uab.cat > > > Tel. +34 93 581 33 53 > > > > > > > > > Campus UAB. Edifici C. 08193 Bellaterra (Barcelona) | *www.creaf.cat* > > > <http://www.creaf.uab.es/cat/index.htm> > > > > > > Abans d'imprimir aquest missatge electrònic penseu en el medi ambient. > > > > > > > > > > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > R-help-es mailing list > > R-help-es@r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-help-es > > > > > > -- > Saludos, > Carlos Ortega > www.qualityexcellence.es > > [[alternative HTML version deleted]] > > _______________________________________________ > R-help-es mailing list > R-help-es@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-help-es > [[alternative HTML version deleted]] _______________________________________________ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es