3D-график с ошибкой R - PullRequest
       27

3D-график с ошибкой R

0 голосов
/ 24 августа 2018

Я пытался построить трехмерный график своих данных, но я не могу понять, как преодолеть некоторые ошибки.Любая помощь высоко ценится.

>head(d1) #produced through the melt function as seen below
     Date variable     value
1 2007 Q2    0.890 1.1358560
2 2007 Q3    0.890 1.1560433
3 2007 Q4    0.890 0.3747925
4 2008 Q1    0.890 0.3866533
5 2008 Q2    0.890 0.3872620
6 2008 Q3    0.890 0.3844887

Мне успешно удалось построить тепловую карту, используя это:

d1<-melt(mydata,id.vars = "Date")
P1 <- ggplot(data=d1, aes(x=Date, y=variable, fill=value)) + 
  geom_tile() +
  ggtitle("My heatmap") +scale_fill_gradientn(colors=colorRampPalette(c("lightgray","royalblue","seagreen","orange","red","brown"))(500),name="Variable") +
  labs(x = "Quarter",y="Alpha") +
  theme_bw()
ggplotly(P1)
*Don't know how to automatically pick scale for object of type yearqtr. Defaulting to continuous.*

enter image description here

Тем не менее, я хочу создать трехмерный график.

open3d()
rgl.surface(x=d1$variable, y=d1$Date, 
            coords=c(1,3,2),z=d1$value, 
            color=colorzjet[ findInterval(d1$value, seq(min(d1$value), max(d1$value), length=100))] )
axes3d()
Error in rgl.surface(x = d1$variable, y = d1$Date, coords = c(1, 3, 2),  : 
'y' length != 'x' rows * 'z' cols


plot_ly(x=d1$Date,y=d1$variable,z=d1$value,type="surface",colors=colors)
Error: `z` must be a numeric matrix
I have tried to use as.matrix(apply(d1,2,as.numeric)), but this returns NAs to the date argument.

Может ли природа квартальных дат портить график?(потому что даже тепловая карта не показывает даты как ежеквартально. Любые подсказки?

dput(d1) вывод здесь: dput (d1) вывод

1 Ответ

0 голосов
/ 26 августа 2018

Загруженный вами файл является файлом CSV, а не dput.Но вы можете прочитать его и построить его так:

d1csv <- read.csv("dput_output.csv")
year <- as.numeric(sub(" .*", "", d1csv$Date))
quarter <- as.numeric(sub(".*Q", "", d1csv$Date))

Date <- matrix(year + (quarter - 1)/4, 55)
variable <- matrix(d1csv$variable, 55)
value <- matrix(d1csv$value, 55)

persp3d(Date, variable, value, col = "red")

Это дает следующий график:

enter image description here

...