Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot2更改图例中的标签_R_Ggplot2_Label - Fatal编程技术网

R ggplot2更改图例中的标签

R ggplot2更改图例中的标签,r,ggplot2,label,R,Ggplot2,Label,我想更改图例中的标签 spi<-read.csv("spill.csv",as.is=TRUE) attach(spi) spi$date<-as.Date(spi$date) str(spi) data.frame: 3184 obs. of 3 variables: $ data1: chr "oil to asset" "oil to asset" "oil to asset" "oil to asset" ... $ date : Date, forma

我想更改图例中的标签

 spi<-read.csv("spill.csv",as.is=TRUE)
 attach(spi)
 spi$date<-as.Date(spi$date)
 str(spi)
 data.frame:   3184 obs. of  3 variables:
 $ data1: chr  "oil to asset" "oil to asset" "oil to asset" "oil to asset" ...
 $ date : Date, format: "2007-01-10" "2007-01-11" ...
 $ sp   : num  7.7 7.95 7.54 7.61 7.67 ...

cont1 <- ggplot(spi,aes(x=date,y=sp,linetype=data1))+geom_line() +
            expand_limits(max(spi$sp), y=c(0,80)) + 
            labs(x = "", y = "") + 
            scale_y_continuous(breaks=seq(0,80,10)) +
            scale_linetype_manual(values = c("dashed","solid")) +  
            scale_x_date(breaks=datebreaks1, labels=date_format("%Y")) +
            ggtitle("Oil and Fianacial Market") +
            annotate("rect", xmin=as.Date("2008-01-02"), xmax=as.Date("2008-06-30"), 
                     ymin=-Inf, ymax=Inf, alpha=.1, fill="blue") +
            theme(legend.position="bottom") + labs(linetype='')  

spi这实际上与@aosmith建议的解决方案相同-将右
断点
(而不是
标签
)添加到您的
缩放线型手册

scale_linetype_manual(values = c("dashed","solid"), breaks=c("oil to asset" ,"asset to oil"))

我还建议您通过
spi$data1将
spi$data1
作为一个系数。您是否试图更改
线型
图例的标签?您需要使用
线型
比例,如
scale\u linetype\u manual
scale\u linetype\u discrete
,而不是
填充
比例。如果附上完全可复制的示例,将更容易为您提供帮助。使用随机数据或与真实数据的链接。