这是我的 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")
我想在同一个图上绘制变量 P 和 T 作为 Date.time 的函数:每个变量都应该有自己的轴。这个函数很简单plot
:
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)
可以用ggplot2做同样的事情吗?我在某处读到可能无法使用 gglot2 绘制双 y 轴图,但这对于 ggplot 等功能强大的包来说很奇怪。