將圖例添加到ggplot 2行圖中我有一個(gè)關(guān)于ggplot 2中傳說的問題。我設(shè)法在同一張圖中繪制了三條線,并希望添加一個(gè)圖例,并使用這三種顏色。這是使用的代碼library(ggplot2) require(RCurl)link<-getURL("https://dl.dropbox.com/s/ds5zp9jonznpuwb/dat.txt")datos<- read.csv(textConnection(link),header=TRUE,sep=";")datos$fecha <- as.POSIXct(datos[,1], format="%d/%m/%Y") temp = ggplot(data=datos,aes(x=fecha, y=TempMax,colour="1")) + geom_line(colour="red") + opts(title="TITULO") + ylab("Temperatura (C)") + xlab(" ") + scale_y_continuous(limits = c(-10,40)) + geom_line(aes(x=fecha, y=TempMedia,colour="2"),colour="green") + geom_line(aes(x=fecha, y=TempMin,colour="2"),colour="blue") + scale_colour_manual(values=c("red","green","blue"))temp以及輸出ggplot three lines我想添加一個(gè)圖例和使用的三種顏色和變量的名稱(TempMax,TempMedia和TempMin)。我試過了scale_colour_manual但找不到確切的路。不幸的是,原始數(shù)據(jù)已從鏈接站點(diǎn)中刪除,無法恢復(fù)。但它們來自于這種格式的meteo數(shù)據(jù)文件。"date","Tmax","Tmin","Tmed","Precip.diaria","Wmax","Wmed"2000-07-31 00:00:00,-1.7,-1.7,-1.7,-99.9,20.4,20.42000-08-01 00:00:00,22.9,19,21.11,-99.9,6.3,2.832000-08-03 00:00:00,24.8,12.3,19.23,-99.9,6.8,3.872000-08-04 00:00:00,20.3,9.4,14.4,-99.9,8.3,5.292000-08-08 00:00:00,25.7,14.4,19.5,-99.9,7.9,3.222000-08-09 00:00:00,29.8,16.2,22.14,-99.9,8.5,3.272000-08-10 00:00:00,30,17.8,23.5,-99.9,7.7,3.612000-08-11 00:00:00,27.5,17,22.68,-99.9,8.8,3.852000-08-12 00:00:00,24,13.3,17.32,-99.9,8.4,3.49
3 回答

鴻蒙傳說
TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
##Subset the necessary columnsdd_sub = datos[,c(20, 2,3,5)]##Then rearrange your data framelibrary(reshape2)dd = melt(dd_sub, id=c("fecha"))
ggplot(dd) + geom_line(aes(x=fecha, y=value, colour=variable)) + scale_colour_manual(values=c("red","green","blue"))
示例圖
- 3 回答
- 0 關(guān)注
- 714 瀏覽
添加回答
舉報(bào)
0/150
提交
取消