How to make a better surface 3dplot with discontinuities in data in R?

64 views Asked by At

I would like to make a surface 3d plot of the data below in R. I already made some figures. However, there are some discontinuities and this effects the plots. Do you have any idea how to make 2 surfaces of it or make it look nice? Thank you! :)

library(scatterplot3d) 
library(rgl) 
library(car) 
x<- b[1:11,2]
y<-seq(-1,1,length.out=21)
z<-matrix(data=b$A,nrow=11,ncol=21)
persp(x,y,z,theta=30, phi=30, col="lightblue",expand = 0.5,shade = 0.2,xlab="c", ylab="h", zlab="A")
scatterplot3d(b$c,b$h,b$A)

surfaceplot scatterplot

structure(list(h = c(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-1, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, 
-0.9, -0.8, -0.8, -0.8, -0.8, -0.8, -0.8, -0.8, -0.8, -0.8, -0.8, 
-0.8, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, -0.7, 
-0.7, -0.6, -0.6, -0.6, -0.6, -0.6, -0.6, -0.6, -0.6, -0.6, -0.6, 
-0.6, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 
-0.5, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, 
-0.4, -0.3, -0.3, -0.3, -0.3, -0.3, -0.3, -0.3, -0.3, -0.3, -0.3, 
-0.3, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, 
-0.2, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, -0.1, 
-0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.1, 0.1, 0.1, 0.1, 0.1, 
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 
0.2, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3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
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 0, 0.1, 0.2, 0.3, 
0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 
0.6, 0.7, 0.8, 0.9, 1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 
0.8, 0.9, 1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 
1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 0, 0.1, 
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 0, 0.1, 0.2, 0.3, 
0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 
0.6, 0.7, 0.8, 0.9, 1), A = c(-0.75, -0.81, -0.87, -0.92, -0.915, 
-0.92, -0.995, -0.985, -0.985, -0.99, -0.99, -0.72, -0.76, -0.82, 
-0.9, -0.92, -0.97, -0.975, -0.98, -0.99, -1, -1, -0.685, -0.775, 
-0.8, -0.87, -0.89, -0.965, -0.945, -0.98, -0.975, -0.995, -1, 
-0.6, -0.695, -0.735, -0.76, -0.89, -0.89, -0.94, -0.93, -0.995, 
-0.99, -0.99, -0.52, -0.595, -0.745, -0.785, -0.885, -0.945, 
-0.935, -0.975, -0.98, -1, -0.99, -0.47, -0.525, -0.645, -0.76, 
-0.785, -0.845, -0.91, -0.925, -0.965, -0.985, 0.76, -0.405, 
-0.42, -0.53, -0.68, -0.775, -0.86, -0.915, -0.945, -0.975, -0.97, 
-1, -0.21, -0.445, -0.465, -0.615, -0.665, -0.785, -0.875, -0.895, 
-0.915, -0.97, -0.98, -0.175, -0.415, -0.365, -0.355, -0.655, 
-0.68, -0.815, -0.86, -0.955, -0.945, 0.91, -0.155, -0.16, -0.145, 
-0.215, -0.36, -0.675, -0.745, 0.76, 0.835, -0.93, 0.935, 0.105, 
-0.055, 0, 0.03, -0.02, -0.075, -0.58, 0.805, -0.845, 0.95, -0.965, 
0.085, 0.19, 0.135, 0.22, 0.42, 0.555, 0.755, 0.875, -0.87, 0.93, 
-0.955, 0.265, 0.345, 0.29, 0.535, 0.535, 0.69, 0.855, 0.875, 
0.915, 0.97, 0.975, 0.31, 0.37, 0.46, 0.595, 0.725, 0.825, 0.875, 
0.92, 0.94, -0.82, 0.98, 0.415, 0.46, 0.495, 0.66, 0.745, 0.81, 
0.92, 0.955, 0.955, 0.975, 0.985, 0.405, 0.575, 0.58, 0.7, 0.775, 
0.89, 0.91, 0.955, 0.98, 0.985, 0.985, 0.515, 0.61, 0.73, 0.795, 
0.865, 0.925, 0.935, 0.955, 0.95, 0.965, 0.995, 0.625, 0.7, 0.745, 
0.845, 0.89, 0.94, 0.94, 0.96, 0.97, 0.98, 0.985, 0.6, 0.72, 
0.745, 0.835, 0.925, 0.91, 0.94, 0.99, 0.98, 0.98, 0.99, 0.8, 
0.705, 0.82, 0.91, 0.93, 0.945, 0.985, 0.98, 0.99, 0.975, 0.99, 
0.805, 0.815, 0.885, 0.91, 0.935, 0.945, 0.98, 0.98, 0.985, 0.995, 
1)), .Names = c("h", "c", "A"), row.names = c(15L, 23L, 43L, 
63L, 82L, 104L, 126L, 148L, 168L, 192L, 212L, 4L, 34L, 46L, 66L, 
87L, 114L, 128L, 147L, 169L, 190L, 211L, 1L, 22L, 47L, 71L, 86L, 
107L, 129L, 149L, 174L, 195L, 213L, 7L, 24L, 42L, 65L, 88L, 108L, 
131L, 151L, 171L, 191L, 214L, 2L, 25L, 45L, 64L, 93L, 109L, 132L, 
152L, 172L, 193L, 217L, 5L, 27L, 44L, 69L, 89L, 113L, 130L, 150L, 
175L, 194L, 216L, 6L, 26L, 48L, 68L, 91L, 110L, 135L, 154L, 173L, 
196L, 215L, 3L, 29L, 55L, 67L, 99L, 112L, 133L, 153L, 176L, 198L, 
218L, 9L, 28L, 53L, 72L, 94L, 111L, 139L, 155L, 178L, 197L, 219L, 
8L, 30L, 50L, 74L, 90L, 116L, 134L, 157L, 184L, 199L, 220L, 10L, 
32L, 54L, 73L, 92L, 115L, 136L, 158L, 177L, 202L, 221L, 14L, 
31L, 51L, 76L, 95L, 117L, 137L, 159L, 182L, 200L, 223L, 17L, 
37L, 52L, 75L, 96L, 118L, 141L, 161L, 179L, 201L, 222L, 12L, 
35L, 56L, 77L, 97L, 119L, 140L, 162L, 180L, 207L, 224L, 13L, 
33L, 70L, 84L, 98L, 120L, 138L, 160L, 183L, 203L, 226L, 11L, 
36L, 57L, 78L, 100L, 121L, 143L, 163L, 185L, 205L, 225L, 16L, 
38L, 59L, 79L, 101L, 127L, 142L, 170L, 181L, 204L, 227L, 19L, 
39L, 58L, 81L, 102L, 122L, 144L, 165L, 186L, 206L, 228L, 18L, 
40L, 61L, 80L, 103L, 123L, 145L, 164L, 187L, 208L, 229L, 20L, 
41L, 60L, 85L, 105L, 125L, 146L, 166L, 188L, 209L, 230L, 21L, 
49L, 62L, 83L, 106L, 124L, 156L, 167L, 189L, 210L, 231L), class = "data.frame")
1

There are 1 answers

0
Derek Corcoran On

First of all you are not really making a wireframe, use the wireframe from the lattice package.

wireframe(A ~  c + h,drape = TRUE,pretty = TRUE, data = df)

This is the result with your data

enter image description here

You still have some wonky Data inbetween, but this should solve the empty spaces.