r - Legend linetypes not displaying properly ggplot -


i have following plot:

ggplot(proba[108:140,], aes(c,four, color="a1")) +     geom_line(linetype=1, size=0.3) +     scale_x_continuous(breaks=seq(110,140,5)) +     theme_bw() +     theme(axis.line = element_line(colour = "black", size=0.25),          panel.grid.major = element_blank(),          panel.grid.minor = element_blank(),          panel.border = element_blank(),          panel.background = element_blank()) +     theme(axis.text.x = element_text(angle = 0, hjust = +0.5, size=6,color="black")) +     theme(axis.text.y = element_text(angle = 0, hjust = -100, size=6, color="black")) +     theme(axis.ticks=element_line(colour="black",size=0.25)) +     xlab("\ntime-steps")+ylab("proportion correct\n") +     theme(axis.text=element_text(size=8),          axis.title=element_text(size=8)) +     geom_line(aes(c,three, color="a2"), size=0.2, linetype=2) +     geom_line(aes(c,one, color="a3"),linetype=3, size=0.8) +     geom_line(aes(c,two, color="a4"), linetype=1, size=0.6) +     scale_color_manual(values=c("a1"="red3", "a2"="red3","a3"="blue3","a4"="blue3")) +     theme(legend.title = element_text(colour="black", size=7)) +     theme(legend.position="bottom" ,          legend.direction="horizontal",           legend.title=theme_blank()) +     theme(legend.text=theme_text(size=7),           legend.background=theme_blank(),           legend.key=theme_blank()) 

the 4 lines on plot displayed in different linetypes, legend not show these different linetypes different colours. missing simple argument in theme() cannot figure out is. maybe need specify linetypes again in scale_colour_manual()?

here's data: https://dl.dropboxusercontent.com/u/22681355/proba.csv

proba<-read.csv("proba.csv",head=t) 

here, correct way in ggplot2:

proba <- read.csv("~/downloads/proba.csv")  proba1 <- proba[108:140,] proba1 <- melt(proba1,id.vars = 1:2)  ggplot(proba1,aes(x = c,y = value,colour = variable,linetype = variable,size = variable)) +      geom_line() +      scale_x_continuous(breaks=seq(110,140,5)) +     scale_colour_manual(values=c("blue3","blue3","red3","red3")) +      scale_linetype_manual(values = c(2,1,3,1)) +      scale_size_manual(values = c(0.2,0.3,0.8,0.6)) +      xlab("\ntime-steps") +      ylab("proportion correct\n") +     theme_bw() +     theme(axis.text=element_text(size=6),           axis.title=element_text(size=8),           axis.line = element_line(size=0.25),           axis.ticks=element_line(size=0.25),           panel.grid.major = element_blank(),           panel.grid.minor = element_blank(),           panel.border = element_blank(),           panel.background = element_blank(),           legend.position="bottom" ,           legend.direction="horizontal",            legend.title=element_blank(),           legend.text=element_text(size=7),            legend.background=element_blank(),            legend.key=element_blank()) 

enter image description here

try keep theme adjustments in 1 call theme, otherwise things pretty messy. also, had calls theme_* should have been element_*.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -