0

Hello I want put another Y axis on the right of the chart with other label (Humidity %):

datos_tem <- dbGetQuery(connection, paste("SELECT temp_int,hum_int,datetime FROM datalog_v2 WHERE host_id=69 and datetime>='2013-10-01' and datetime<='2013-10-03';", 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("Temperature") +
   ylab("Time")

This produce:

enter image description here

Thanks in advance.

ManuParra
  • 1,471
  • 6
  • 18
  • 33
  • I just only want put one Y axis on the right side with label "Himidity", your link don't do what I want. No facets, only Y axis, same scale. – ManuParra Feb 18 '14 at 22:04
  • @ManuParra You should read more carefully. In particular, the second answer, by the author of ggplot. – joran Feb 18 '14 at 22:18
  • That said, anything is technically possible (though difficult) if you are [willing to delve into the grid code](http://rpubs.com/kohske/dual_axis_in_ggplot2). – joran Feb 18 '14 at 22:19
  • Thanks for the responses, well I'll put in Y axis both measures. – ManuParra Feb 18 '14 at 22:34
  • If it's the same scale then why do you need another axis? Just rename the y axis and make the legend say which is temperature and which is humidity – JeremyS Feb 19 '14 at 01:26

0 Answers0