第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

將圖例添加到ggplot 2行圖中

將圖例添加到ggplot 2行圖中

慕少森 2019-06-10 16:31:01
將圖例添加到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è)贊

我傾向于發(fā)現(xiàn),如果我在多個(gè)geom‘s中指定單個(gè)顏色,我就做錯(cuò)了。以下是我如何繪制您的數(shù)據(jù):

##Subset the necessary columnsdd_sub = datos[,c(20, 2,3,5)]##Then rearrange your data framelibrary(reshape2)dd = melt(dd_sub, id=c("fecha"))

剩下的只是一個(gè)簡(jiǎn)單的ggplote命令:

ggplot(dd) + geom_line(aes(x=fecha, y=value, colour=variable)) +
  scale_colour_manual(values=c("red","green","blue"))

示例圖


查看完整回答
反對(duì) 回復(fù) 2019-06-10
  • 3 回答
  • 0 關(guān)注
  • 714 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)