this is a piece of my df:
structure(list(Date.time = structure(c(1372846200, 1372846800,
1372847400, 1372848000, 1372848600, 1372849200, 1372849800, 1372850400,
1372851000, 1372851600, 1372852200, 1372852800, 1372853400, 1372854000,
1372854600, 1372855200, 1372855800, 1372856400, 1372857000, 1372857600,
1372858200, 1372858800, 1372859400, 1372860000, 1372860600, 1372861200,
1372861800, 1372862400, 1372863000, 1372863600), class = c("POSIXct",
"POSIXt"), tzone = ""), P = c(1114.3, 1114.5, 1114.3, 1114.1,
1114.1, 1113.9, 1114.1, 1113.9, 1113.9, 1113.9, 1114.1, 1113.9,
1114.1, 1113.9, 1113.9, 1113.9, 1113.9, 1113.9, 1113.7, 1114.3,
1114.1, 1114.3, 1114.3, 1114.3, 1114.3, 1114.3, 1114.3, 1114.3,
1114.3, 1114.5), T = c(11.92, 11.92, 11.92, 11.92, 11.92, 11.93,
11.93, 11.93, 11.93, 11.93, 11.93, 11.93, 11.94, 11.94, 11.94,
11.94, 11.94, 11.94, 11.94, 11.94, 11.94, 11.94, 11.94, 11.94,
11.95, 11.94, 11.94, 11.95, 11.94, 11.94), ID = c("J9335", "J9335",
"J9335", "J9335", "J9335", "J9335", "J9335", "J9335", "J9335",
"J9335", "J9335", "J9335", "J9335", "J9335", "J9335", "J9335",
"J9335", "J9335", "J9335", "J9335", "J9335", "J9335", "J9335",
"J9335", "J9335", "J9335", "J9335", "J9335", "J9335", "J9335"
)), .Names = c("Date.time", "P", "T", "ID"), row.names = c(NA,
30L), class = "data.frame")
I want to plot on the same plot the variable P and T as function of Date.time: each variable should have its own axis. It's quite simple with the plot
function:
plot(df$Date.time, df$P, type="l")
par(new=T)
plot(df$Date.time, df$T, type="l", col="blue", yaxt="n", xaxt="n", xlab="n", ylab="n")
axis(4)
Is it possible to do the same thing with ggplot2? I read somewhere that it might be impossible to plot a double y axis graph with gglot2, but that's weird for a powerful package as ggplot.