单列的3D功能区图

时间:2019-06-28 09:18:31

标签: r plot 3d ribbon

我能够为行和列的尺寸大于1的矩阵创建ribbon3D图。当其中一个维度为1时,我遇到了一个问题。这意味着如果我有12行和一列,则我的代码给出了错误。 需要帮助解决这种情况。

表的示例数据如下:

    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")))

用于绘图的代码如下:

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)

对于那些对大于1的矩阵如何工作感兴趣的人。这是示例数据。但是在代码中将矩阵名称从rs12更改为tf12。 通过在上面的示例上运行上面的代码而导致的错误是这样的,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")))

1 个答案:

答案 0 :(得分:1)

这是由ribbon3D中的一个错误引起的:它是一个矩阵的子集,但是没有告诉R将其保留为矩阵,因此它变成了向量,之后情况就很糟了。

您可以使用fix()函数自己编辑该错误,然后编辑并创建本地副本,但最终会出现一个不同的错误,很可能是由其他地方的相同问题引起的。

我建议您有两个选择:

  1. 花一些时间来查找和解决所有这些问题。这是学习R中调试的好机会,但需要一段时间。修复所有问题后,请将必要的更改列表发送到plot3D软件包的维护者。

  2. 写给维护者,包括您可以复制的示例,并希望她有兴趣和时间来解决此问题。