我是新来的,对R也比较陌生。
我想将热图转换为曲面3D图。
我有一个包含2列的excel文件:日期(天/毫米/年小时:分钟)和转换率平均每小时(t/h)我设法创建了热图与变异(日(日期),月(日期,label=true)来创建X的小时,Y=days和值我的转换率。月/年的方面。
现在,我想在一个月内使用表面3D,其中X:小时,y:天,Z:转换率
如何将我的数据框从excel转换为这个,以创建3D表面(如火山的例子)
发布于 2021-01-23 22:51:51
好了,我终于得到了我想要的。
df<-test3 # test3 is a import file from exel, with two columns, date and conversion rate
df <- df %>% mutate(year = year(date),
month = month(date, label=TRUE),
day = day(date), hour=hour(date)) #Transform to date, month, day, hour, conversion rate
df2020<-filter(df,year==2020)
dfabr<-filter(df2020,month=="abr") #Filter for year 2020 and month april , looks like this
stationid day hour month year rate
<chr> <int> <int> <ord> <dbl> <dbl>
1 Tasa Fusión HF, t/h 1 0 abr 2020 127.
2 Tasa Fusión HF, t/h 1 1 abr 2020 130.
3 Tasa Fusión HF, t/h 1 2 abr 2020 130.
---
**df_4=data.frame("x"=c(dfabr$day),"y"=c(dfabr$hour),"z"=c(dfabr$rate))** #Imported and filtered data to MATRIX
library(reshape2) #for use in plotly 3d surface graphs like volcano example
**df3d<-acast(df_4,x~y, value.var="z",sum)** #acast return matrix format, I add SUM because with a large data, i got message "Aggregation function missing: defaulting to length", I have no idea why, but when i used a small dataset with exact same code, i didn't get that. When i added "sum", error message disapeared
library(plotly)
p <- plot_ly(z = df3d, type = "surface")
p 啊,真灵!X表示日期的小时数,y表示一个月的天数,z表示换算率的值。

https://stackoverflow.com/questions/65859375
复制相似问题