I am able to create the ribbon3D plot for a matrix which has dimensions greater than 1 for rows and columns. I am stuck with a problem when one of the dimensions is 1. meaning if I have 12 rows and a single column then my code gives an error. Need help in solving this situation.
The sample data of a table is given as follows:
structure(c(3, 4, 2, 2, 9, 6, 6, 7, 8, 10, 11), .Dim = c(1L,
11L), .Dimnames = list("Fruits and nuts (excluding oil nuts), fresh or dried",
c("2005", "2006", "2007", "2008", "2009", "2010", "2011",
"2012", "2013", "2014", "2015")))
The code used for plots is as follows:
library(plot3D)
ribbon3D(x = 1:nrow(rs12), y = 1:ncol(rs12), z = rs12, scale = T, expand = .2, bty = "b", along = "y",
colvar = rs12, colkey = F, border = "black", shade = 0.1,
theta = -50, phi = 40, space = .5, d = 2,
curtain = T, xlab = "", ylab = "", zlab = "", main = "Pakistan's Exports to Russia",
cex.axis = 0.000000000001, box = F)
For those who are interested in how it works for matrix greater than 1. Here is the sample data. But change the matrix name from rs12
to tf12
in the code.
The error by running the above code on the above sample is like this, Error in persp.default(plist$xlim, plist$ylim, z = matrix(nrow = 2, ncol = 2, : increasing 'x' and 'y' values expected
.
dput(tf12)
structure(c(18, 36, 18, 39, 41, 18, 18, 18, 18, 36, 37, 18, 38,
18, 18, 18, 40, 18, 18, 17, 36, 17, 39, 41, 17, 17, 17, 34, 38,
36, 17, 34, 17, 17, 17, 40, 17, 17, 16, 38, 34, 40, 41, 16, 16,
16, 16, 36, 36, 16, 34, 34, 34, 16, 39, 16, 16, 32, 40, 32, 40,
41, 32, 32, 32, 14, 36, 36, 14, 14, 32, 32, 14, 38, 14, 14, 16,
38, 33, 39, 41, 33, 16, 33, 33, 37, 36, 16, 33, 16, 16, 16, 40,
16, 16, 14, 39, 31, 40, 41, 31, 31, 31, 31, 37, 36, 31, 14, 31,
14, 31, 38, 14, 31, 30, 37, 30, 39, 41, 36, 13, 30, 30, 38, 30,
30, 30, 30, 30, 30, 40, 13, 13, 15, 38, 32, 39, 41, 32, 15, 15,
32, 38, 32, 32, 15, 32, 36, 15, 40, 15, 15, 15, 38, 32, 39, 41,
36, 15, 15, 32, 38, 32, 32, 15, 15, 32, 15, 40, 32, 15, 15, 38,
32, 39, 41, 36, 15, 15, 32, 32, 32, 36, 15, 32, 36, 15, 40, 15,
15, 16, 38, 34, 39, 41, 37, 16, 16, 34, 16, 34, 16, 16, 34, 34,
16, 40, 16, 16), .Dim = c(19L, 11L), .Dimnames = list(c("Pig iron & spiegeleisen, sponge iron, powder & granu",
"Ores and concentrates of base metals, n.e.s.", "Waste, parings and scrap, of plastics",
"Leather", "Textile yarn", "Stone, sand and gravel", "Fish, dried, salted or in brine; smoked fish",
"Copper", "Non-ferrous base metal waste and scrap, n.e.s.", "Cotton",
"Fish, fresh (live or dead), chilled or frozen", "Feeding stuff for animals (no unmilled cereals)",
"Carboxylic acids, anhydrides, halides, per.; derivati.", "Crustaceans, mollusks and aquatic invertebrates",
"Crude vegetable materials, n.e.s.", "Polymers of ethylene, in primary forms",
"Cotton fabrics, woven", "Other crude minerals", "Ships, boats & floating structures"
), c("2005", "2006", "2007", "2008", "2009", "2010", "2011",
"2012", "2013", "2014", "2015")))
This is caused by a bug in ribbon3D
: it subsets a matrix, but doesn't tell R to keep it as a matrix, so it becomes a vector, and things go badly after that.
You can fix that bug yourself using the fix()
function to edit it and create a local copy, but you'll just end up with a different error, likely caused by the same issue elsewhere.
I'd suggest you have two choices:
Spend some time tracking down and fixing all of these problems. It's a good chance to learn debugging in R, but will take a while. Once you have them all fixed, send the list of necessary changes to the maintainer of the plot3D
package.
Write to the maintainer, including your reproducible example, and hope that she has interest and time to fix the issue.