如何解决我如何在 R 中绘制 3d 直方图?
我有一个带有数字的表格,可以在 excel 中绘制 3d 直方图。 这是我在 excel 中的直方图:
我如何在 R 中使用 plot3d 做同样的事情? 在他们的示例中,他们使用 3 位数字表示 x、y、z。 这是他们在 R 中的数据集和直方图:
但我只有一个数字表示一栏 我的桌子:
-2.88 -1.76 -0.41 -2.25 -0.83 -0.62 -1.25 -2.68 -2.41 -1.74 -2.51 -0.78 -1.97 -2.67 -1.41 -1.56 0.49 -1.54 -1.37 -1.47 -2.32 0.66
-2.39 -1.98 -0.65 -2.33 -1.98 -1.19 -2.44 -2.13 -2.16 -2.44 -2.20 -1.77 -0.60 -0.73 -0.77 -1.59 -1.01 -1.37 -1.68 -0.92 -1.28 -0.12
-1.99 -2.48 -0.43 -1.75 -1.81 -2.37 -1.08 -1.18 -0.80 -3.30 -2.04 -1.96 -0.65 -2.44 -0.83 -1.67 -0.48 -1.03 -1.76 0.04 -1.30 -0.71
-2.73 -2.22 -0.98 -1.24 -2.21 -1.29 -1.37 -0.89 -0.86 -2.22 -1.32 -2.13 -1.04 -1.12 -0.60 -1.58 0.20 0.01 -1.81 -0.17 -0.38 -1.74
-1.63 -1.29 -1.31 -1.94 -2.39 -1.20 -1.66 -0.14 -0.96 -1.10 -0.40 -1.29 -0.44 -0.26 0.01 -2.71 -0.55 0.17 -3.44 -0.95 0.75 -1.08
-0.95 -0.15 -1.13 -1.18 -1.74 0.09 -1.12 -0.37 -0.80 -0.44 -1.18 -1.53 -1.28 0.36 -0.56 -1.54 -0.58 0.71 -1.53 -0.57 -0.91 -1.29
-0.67 0.02 -1.82 -0.84 -2.11 -0.38 -1.12 -0.57 -0.81 -1.04 -1.22 -0.93 -1.29 -0.26 0.02 -0.76 -0.28 -0.24 -0.43 -0.37 -1.30 -1.61
-3.45 -2.79 -0.44 -2.25 -0.81 -1.00 -1.20 -2.90 -1.96 -2.79 -2.91 -0.58 -1.65 -3.10 -1.23 -2.20 -0.15 -1.60 -1.51 -0.97 -2.35 0.38
-3.03 -3.12 -0.62 -2.01 -2.25 -1.84 -2.29 -2.51 -1.86 -2.93 -2.32 -1.63 -0.35 -1.05 -1.09 -2.04 -0.79 -1.18 -2.39 -0.54 -0.60 -0.71
-2.78 -2.60 -0.49 -1.69 -1.96 -2.10 -1.70 -1.26 -0.37 -2.80 -2.40 -2.23 -0.61 -2.26 -0.80 -2.11 -0.17 -0.21 -2.61 -0.09 -1.18 -1.26
-3.13 -1.96 -1.19 -1.17 -2.76 -0.87 -1.96 -0.22 -0.49 -2.75 -1.81 -2.48 -1.26 -1.04 0.08 -2.52 0.21 0.80 -2.28 -0.14 -0.27 -1.69
-1.52 -1.85 -1.36 -1.42 -2.28 -0.49 -1.58 -0.34 -1.11 -0.59 -0.74 -1.63 -0.58 -0.23 0.12 -2.97 0.17 0.68 -3.14 -0.64 0.21 -1.70
-1.05 -0.42 -1.50 -1.46 -2.32 -0.57 -0.63 -0.17 -0.79 -0.92 -1.52 -1.69 -1.25 0.34 -0.46 -1.94 0.27 0.82 -1.48 0.35 -1.25 -1.89
-1.03 0.28 -1.39 -0.82 -2.44 -0.75 -0.86 -0.69 -1.07 -1.38 -1.46 -1.09 -1.71 -0.50 0.59 -1.42 -0.54 -0.13 -0.86 -0.14 -1.28 -1.84
更新: 我尝试将完整数据集插入其中一个示例。只是想看看 plot3 如何处理大量条形。它非常卡住。 我没有看到负面的酒吧。我假设正条会出现在 0 上和负下,就像我的第一张照片一样。
所以,我意识到首先我需要渲染大量数据才能选择正确的库。 我还假设,对于那么多数据来说,完整的实时 3d 渲染可能是不可能的。因此,如果库像 hist3d 那样仅渲染 1 张图片,那将是正常的。
m <- structure(c(-2.88,-1.76,-0.41,-2.25,-0.83,-0.62,-1.25,-2.68,-2.41,-1.74,-2.51,-0.78,-1.97,-2.67,-1.41,-1.56,0.49,-1.54,-1.37,-1.47,-2.32,0.66,-2.39,-1.98,-0.65,-2.33,-1.19,-2.44,-2.13,-2.16,-2.20,-1.77,-0.60,-0.73,-0.77,-1.59,-1.01,-1.68,-0.92,-1.28,-0.12,-1.99,-2.48,-0.43,-1.75,-1.81,-2.37,-1.08,-1.18,-0.80,-3.30,-2.04,-1.96,-1.67,-0.48,-1.03,0.04,-1.30,-0.71,<=-=-=-=-=-=-=-=-=-=-=-skipped ==============>>
-2.64,-0.89,-1.60,-2.28,-3.56,-0.84,0.31,0.48,-0.31,0.03,-2.42,0.92,-3.10,-2.35,-2.56,-0.91,1.01,-5.90,-0.40,2.95,-1.32,-3.06,-0.69,-0.74,-2.46,-4.16,0.46,0.97,-0.47,-0.79,-3.12,1.09,-3.53,-0.25,-1.26,-0.57,0.67,-4.76,0.01,-0.08,-2.70,-0.97,-2.40,-5.45,1.65,0.24,-1.79,-2.05,0.18,-3.01,-0.39,0.47,-2.21,-0.50,0.77,-3.05,0.81,-0.36,-1.98),.Dim = c(700L,22L))
library(graph3d)
dat <- cbind(
expand.grid(x = 1:700,y = 1:22),z = c(m)
)
graph3d(
dat,~x,~y,~z,type = "bar"
)
请帮我从一个完整的 txt 文件中绘制一个直方图,上面有正的向上柱和负的向下。
我的完整 txt 文件在这里https://pastebin.com/2zyyRDy8
我已将我的 txt 文件读到 res_cut,但我看到数据结构与您的示例不同,在我那里有 700 个 23 个变量的 objs
res_cut <- read.delim("d:/result_cut.txt",sep = "\t",header = FALSE)
解决方法
使用 graph3d
包:
m <- structure(c(-2.88,-2.39,-1.99,-2.73,-1.63,-0.95,-0.67,-3.45,-3.03,-2.78,-3.13,-1.52,-1.05,-1.03,-1.76,-1.98,-2.48,-2.22,-1.29,-0.15,0.02,-2.79,-3.12,-2.6,-1.96,-1.85,-0.42,0.28,-0.41,-0.65,-0.43,-0.98,-1.31,-1.13,-1.82,-0.44,-0.62,-0.49,-1.19,-1.36,-1.5,-1.39,-2.25,-2.33,-1.75,-1.24,-1.94,-1.18,-0.84,-2.01,-1.69,-1.17,-1.42,-1.46,-0.82,-0.83,-1.81,-2.21,-1.74,-2.11,-0.81,-2.76,-2.28,-2.32,-2.44,-2.37,-1.2,0.09,-0.38,-1,-1.84,-2.1,-0.87,-0.57,-0.75,-1.25,-1.08,-1.37,-1.66,-1.12,-2.29,-1.7,-1.58,-0.63,-0.86,-2.68,-2.13,-0.89,-0.14,-0.37,-2.9,-2.51,-1.26,-0.22,-0.34,-0.17,-0.69,-2.41,-2.16,-0.8,-0.96,-1.86,-1.11,-0.79,-1.07,-3.3,-1.1,-1.04,-2.93,-2.8,-2.75,-0.59,-0.92,-1.38,-2.2,-2.04,-1.32,-0.4,-1.22,-2.91,-2.4,-0.74,-0.78,-1.77,-1.53,-0.93,-0.58,-2.23,-1.09,-1.97,-0.6,-1.28,-1.65,-0.35,-0.61,-1.71,-2.67,-0.73,-0.26,0.36,-3.1,-2.26,-0.23,0.34,-0.5,-1.41,-0.77,0.01,-0.56,-1.23,0.08,0.12,-0.46,0.59,-1.56,-1.59,-1.67,-2.71,-1.54,-0.76,-2.52,-2.97,0.49,-1.01,-0.48,0.2,-0.55,-0.28,0.21,0.17,0.27,-0.54,0.71,-0.24,-1.6,-0.21,0.8,0.68,0.82,-0.13,-1.68,-3.44,-1.51,-2.61,-3.14,-1.48,-1.47,0.04,-0.97,-0.09,-0.64,0.35,-1.3,0.75,-0.91,-2.35,-0.27,0.66,-0.12,-0.71,-1.61,0.38,-1.89,-1.84),.Dim = c(14L,22L))
library(graph3d)
dat <- cbind(
expand.grid(x = 1:14,y = 1:22),z = c(m)
)
graph3d(
dat,~x,~y,~z,type = "bar"
)
,
您可以使用 hist3D
包中的 plot3D
和 z
参数:
m <- structure(c(-2.88,22L))
plot3D::hist3D(z=m)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。