曲面图可以直接从R中的每日数据的时间序列创建吗?该曲面的x轴为月份,y轴为年份,z轴为数值。
dt <- seq(as.Date('2006-01-01'),as.Date('2020-01-31'),by = 1) temp <- rnorm(5144, mean=21, sd=5) df <- data. Frame(dt, temp)
字符串
pexxcrt21#
我假设temp是temperature的缩写。考虑到你的玩具数据,heatmap似乎是合适的
temp
temperature
heatmap
dt <- seq(as.Date('2006-01-01'),as.Date('2020-01-31'),by = 1) temp <- rnorm(5144, mean = 21, sd = 5) df <- data.frame(dt, temp) library(dplyr) library(lubridate) library(plotly) df |> mutate(month = month(dt), year = year(dt)) |> plot_ly(x = ~ month, y = ~ year, z = ~ temp, type = 'heatmap')
字符串给
曲面图需要将矩阵传递给z,请参见?add_surface。
z
?add_surface
thtygnil2#
如果您要查找3D表面打印,则可以转换为矩阵格式并使用plotly打印
plotly
dt <- seq(as.Date('2006-01-01'), as.Date('2020-12-31'), by = 1) temp <- rnorm(length(dt), mean = 21, sd = 5) df <- data.frame(dt, temp) library(plotly) df$month <- as.numeric(substr(df$dt, 6, 7)) df$year <- as.numeric(substr(df$dt, 1, 4)) df <- aggregate(temp ~ year + month, data = df, mean) m <- matrix(df$temp, ncol = 12) dimnames(m) <- list(sort(unique(df$year)), sort(unique(df$month))) plot_ly(z = ~m) |> add_surface() |> layout(scene = list(yaxis = list(title = "Year", tickvals = 0:14, ticktext = 2006:2020), xaxis = list(title = "Month", tickvals = 0:11, ticktext = month.abb), zaxis = list(title = "Temperature")))
2条答案
按热度按时间pexxcrt21#
我假设
temp
是temperature
的缩写。考虑到你的玩具数据,heatmap
似乎是合适的字符串
给
曲面图需要将矩阵传递给
z
,请参见?add_surface
。thtygnil2#
如果您要查找3D表面打印,则可以转换为矩阵格式并使用
plotly
打印字符串