1

我有以下情节:

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())

图上的四条线以不同的线型显示,但图例并未显示这些不同的线型,仅显示不同的颜色。我显然在 theme() 中遗漏了一个非常简单的论点,但我无法弄清楚它是什么。也许我需要在 scale_colour_manual() 中再次指定线型?

这是数据:https ://dl.dropboxusercontent.com/u/22681355/proba.csv

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

1 回答 1

4

在这里,这是在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())

在此处输入图像描述

尝试在一次调用中保留所有主题调整theme,否则事情会变得非常混乱。此外,你有一些电话theme_*应该是element_*.

于 2013-08-07T15:57:25.110 回答