0
我想更改圖例中的標籤。ggplot2更改圖例中的標籤
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='')
然後我想將資產轉換成石油和石油轉爲資產。
我該如何改變?
scale_fill_discrete(labels=c("oil to asset" ,"asset to oil"))
這是行不通的。
請幫幫我。
你想改變'linetype'圖例的標籤嗎?您需要使用'linetype'比例來做到這一點,比如'scale_linetype_manual'或'scale_linetype_discrete',而不是'fill'比例。 – aosmith 2014-10-17 22:16:13
如果連接完全可重複的示例,那將會更容易幫助您。隨機數據或與實際數據的鏈接。 – 2014-10-18 08:23:35