0

I'm looking to create some 3d surface plots with some data in R. I've got a large dataframe of many variables, but I'm only interested in displaying 3 (the distance, the year, and the mortality rate). I've been trying to use the surface plot library for a day or two now, and I can't get anything to display. I can get the other libraries to work. Here's the code I'm working with at the moment -

cold3Dplot <- plot_ly(showscale = FALSE) %>%
  add_surface(z = ~as.matrix(filtered$distance,2014,filtered$RelativeDeaths.2014),opacity = 0.98) %>%
  add_surface(z = ~as.matrix(filtered$distance,2015,filtered$RelativeDeaths.2015),opacity = 0.98) %>%
  add_surface(z = ~as.matrix(filtered$distance,2016,filtered$RelativeDeaths.2016),opacity = 0.98)%>%
  add_surface(z = ~as.matrix(filtered$distance,2017,filtered$RelativeDeaths.2017),opacity = 0.98)

cold3Dplot

This is what my filtered data frame looks like:

   datazone              label      code shape_area shape_leng stdareakm2 stdareaha hhcnt2011 respop2011 totpop2011
561 S01010318 S12000046S01010318 S01010318  128009.62   2950.044   0.128009 12.800961       304        505       1588
562 S01010319 S12000046S01010319 S01010319   96160.88   2282.814   0.096161  9.616090       407        711        711
599 S01010356 S12000046S01010356 S01010356  286149.89   4874.812   0.286150 28.614989       308        682        682
606 S01010363 S12000046S01010363 S01010363  157714.24   3083.966   0.157714 15.771425       394        758        758
563 S01010320 S12000046S01010320 S01010320   73061.83   1544.579   0.073063  7.306183       437        670        675
709 S01010466 S12000046S01010466 S01010466  529203.94   4393.694   0.529203 52.920395       458        879        879
                    name Feature.Name RelativeDeaths.2014 RelativeDeaths.2015 RelativeDeaths.2016 RelativeDeaths.2017
561         Ruchill - 04           NA                  -5                  -5                  -3                  -4
562         Ruchill - 05           NA                  -6                  -5                  -6                  -6
599   Maryhill West - 03           NA                  -5                  -6                  -2                  -9
606      Kelvindale - 01           NA                  -2                  -2                  -5                  -5
563         Ruchill - 06           NA                  -4                  -6                  -3                  -6
709 Anniesland East - 02           NA                  -5                  -7                  -3                   0
    AverageRelativeDeaths  distance       lon      lat ID OBJECTID                 Name TotPop2011 ResPop2011 HHCnt2011
561                    -4  30.44933 -4.278552 55.88277 24     3813         Ruchill - 04       1588        505       304
562                    -6  32.69077 -4.280502 55.88595 23     3814         Ruchill - 05        711        711       407
599                    -6  50.42398 -4.287960 55.89284 32     3851   Maryhill West - 03        682        682       308
606                    -4 105.39898 -4.309206 55.89306 10     3858      Kelvindale - 01        758        758       394
563                    -5 149.88008 -4.282008 55.88644 23     3815         Ruchill - 06        675        670       437
709                    -4 154.92867 -4.319477 55.89498 72     3961 Anniesland East - 02        879        879       458
    Easting Northing coords.x1 coords.x2 optional
561  257542   667848 -4.278992  55.88265     TRUE
562  257447   668188 -4.280688  55.88567     TRUE
599  256994   669045 -4.288377  55.89323     TRUE
606  255670   668966 -4.309488  55.89213     TRUE
563  257256   668176 -4.283733  55.88551     TRUE
709  254973   669173 -4.320734  55.89378     TRUE

But like I said, I'm only interested in using the Relative Deaths, distance and year from it.

What am I doing wrong exactly? I'd like to get something to show at least and then I can see if I'm going in the right direction or not.

Cheers!

  • 1
    You need to put together a complete example. We don't know what `filtered` looks like. It doesn't need to be your real data, it just needs to reproduce the problem. – user2554330 Aug 18 '19 at 13:31
  • agree - posting your filtered data would help --- also, your use of as.matrix may be part of the problem - if you want to build a matrix from 3 columns of your data frame columns use something like: `cbind(filtered$distance, 2014, filtered$RelativeDeaths.2014)` – Ben Aug 18 '19 at 13:34
  • Sorry, please find the dataframe attached to the original question. – Murray Ross Aug 18 '19 at 13:54
  • Please see [this link](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for how to convey your data in a concise and copy/pasteable manner. – Roman Luštrik Aug 18 '19 at 14:54

0 Answers0