更改图例名称和图例值以及其他内容

时间:2014-02-18 22:58:43

标签: r charts legend lines

您好,这是我的代码:

datos_tem <- dbGetQuery(connection, paste("SELECT temp_int,hum_int,datetime FROM datalog_v2 WHERE host_id=69 and datetime>='2013-10-01 00:00:00' and datetime<='2013-10-01 23:59:00';", sep=""))
dbDisconnect(connection)

datos_tem$datetime <- as.POSIXct(datos_tem$datetime)
datos_tem$temp_int <- as.numeric(datos_tem$temp_int)
datos_tem$hum_int <- as.numeric(datos_tem$hum_int)


#gg <- qplot(datos_tem$datetime, datos_tem$temp_int) + geom_line()        # first line
#gg <- gg + geom_line(aes( x=datos_tem$datetime, y=datos_tem$hum_int )) # add the second line!

Molten <- melt(datos_tem, id.vars = "datetime")
print(Molten)
ggplot(Molten, aes(x = datetime, y = value, colour = variable)) + geom_line() +
  scale_y_continuous(limits=c(0, 100)) +
   xlab("Time") +
   ylab("Temperature")+ 
  scale_color_manual(values=c("#FF0000", "#0000FF"))+
  opts(panel.background = theme_rect(fill='white'))+
  geom_line(size=1.9)

并制作:

enter image description here

但是我已经尝试了一百件事情来改变传奇名称和图例名称值(temp_int和hum_int必须更改为“温度”和“湿度”以及“Medidas”可变的lengend名称)。

提前致谢!

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

+ scale_color_manual(values=c("#FF0000", "#0000FF"), 
                   name="Medidas",
                   labels=c("Temperature", "Humidity"))