[英]Create a filled.contour plot with time (POSIXct) on x axis
I want to make a plot with time on x axis, depth on y axis and temperature as z values. 我想用x轴上的时间,y轴上的深度和温度作为z值绘制图。 I converted time into the posixct format:
我将时间转换为posixct格式:
DateTime<-as.character.Date(Rohdaten$Datum..UTC.)
CompleteDate <- as.POSIXct(DateTime, format = "%d.%m.%Y %H:%M", tz = "UTC")
These are the depths: 这些是深度:
Tiefen <- c(1, 3, 5, 10, 15, 20.5)
And my temperature values are in a matrix: 我的温度值在一个矩阵中:
Temp <- as.matrix(data.frame(Daten$D1.1m, Daten$D1.3m, Daten$D1.5m, Daten$D1.10m, Daten$D1.15m, Daten$D1.20.5m))
Temp2 <- matrix(Temp, ncol=ncol(Temp), dimnames = NULL)
I use this code to make the plot: 我使用以下代码进行绘制:
filled.contour(CompleteDate,Tiefen,Temp2)
But I get an error message: 但是我收到一条错误消息:
Error in filled.contour(CompleteDate, Tiefen, Temp2) :
ansteigende 'x' und 'y' Werte erwartet
This error says that filled.contour expects ascending x and y values. 该错误表明,fill.contour期望x和y值递增。 When I take
当我拿
Time <- c(1:3405)
Instead of the time in the posixct format the plot is created: 代替以posixct格式的时间创建图:
What can I do to take my actual dates and times as the x axis? 我该怎么做才能将实际的日期和时间作为x轴?
Here are my CompleteDates in the POSIXct format: https://www.dropbox.com/s/f0h643u7lpzq9mu/CompleteDate.txt?dl=0 这是我的POSIXct格式的CompleteDate: https ://www.dropbox.com/s/f0h643u7lpzq9mu/CompleteDate.txt ? dl =0
Here is a working example using only a snapshot of your Dates and fictional Temperatures: 这是一个仅使用日期和虚拟温度快照的工作示例:
DateTime <- structure(c(1472209200, 1472212800, 1472216400, 1472220000, 1472223600,
1472227200, 1472230800, 1472234400, 1472238000, 1472241600, 1472245200,
1472248800, 1472252400, 1472256000, 1472259600, 1472263200, 1472266800,
1472270400, 1472274000, 1472277600, 1472281200, 1472284800, 1472288400,
1472292000, 1472295600, 1472299200, 1472302800, 1472306400, 1472310000,
1472313600, 1472317200, 1472320800, 1472324400, 1472328000, 1472331600
), class = c("POSIXct", "POSIXt"), tzone = "UTC")
Tiefen <- c(1, 3, 5, 10, 15, 20.5)
# now create fictive temperatures
df <- expand.grid("Date" = DateTime, "Tiefen" = Tiefen)
df <- df %>% group_by(Tiefen) %>% mutate(Temp = runif(n(), 15 - Tiefen/2, 27 - Tiefen)) %>% ungroup()
Temp <- matrix(df$Temp, nrow = length(DateTime))
inMeter <- function(x) {
paste0(x, "m")
}
inCelsius <- function(x) {
paste0(x, "°C")
}
filled.contour(x = as.numeric(DateTime), y = Tiefen, z = Temp,
plot.axes = {
axis(1, labels = DateTime, at = as.numeric(DateTime), las = 2, cex.axis = 0.5)
axis(2, at = Tiefen, labels = inMeter(Tiefen), cex.axis = 1)
},
key.axes = {
axis(4, at = pretty(Temp), labels = inCelsius(pretty(Temp)))
})
Notes: 笔记:
as.numeric()
) as x values for the plot. as.numeric()
)作为绘图的x值。 z
values ( Temp
) are supplied as a matrix which has as many rows as we have x values. z
值( Temp
)作为矩阵提供,该矩阵具有与x值一样多的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.