-1

我有一个带有数字的表格,可以在 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   

UPD:我尝试将完整的数据集插入其中一个示例。只是想看看 plot3 如何处理大量条形图。它很卡。而且我没有看到负面的酒吧。我假设正条将出现在上 0 和负底部,就像我的第一张照片一样。

所以,我意识到首先我需要渲染大量数据才能选择正确的库。我还假设,对于这么多的数据,完整的实时 3d 渲染可能是不可能的。因此,如果库像 hist3d 那样只渲染一张图片,那将是正常的。 当前结果

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.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, 
            <=-=-=-=-=-=-=-=-=-=-=-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, 0.03, -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.46, -0.47, -0.79, -3.12, 1.09, -3.53, -1.08, -0.25, -1.26, -0.57, 0.67, -4.76, 0.01, -0.08, -1.56, 
             -2.70, -0.89, -0.97, -2.40, -5.45, -1.26, 1.65, 0.24, -1.60, -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 个 objs 的 23 个变量

res_cut <- read.delim("d:/result_cut.txt",sep = "\t", header = FALSE)

读分隔符

4

2 回答 2

5

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.25, -2.01, -1.69, 
                 -1.17, -1.42, -1.46, -0.82, -0.83, -1.98, -1.81, -2.21, -2.39, 
                 -1.74, -2.11, -0.81, -2.25, -1.96, -2.76, -2.28, -2.32, -2.44, 
                 -0.62, -1.19, -2.37, -1.29, -1.2, 0.09, -0.38, -1, -1.84, -2.1, 
                 -0.87, -0.49, -0.57, -0.75, -1.25, -2.44, -1.08, -1.37, -1.66, 
                 -1.12, -1.12, -1.2, -2.29, -1.7, -1.96, -1.58, -0.63, -0.86, 
                 -2.68, -2.13, -1.18, -0.89, -0.14, -0.37, -0.57, -2.9, -2.51, 
                 -1.26, -0.22, -0.34, -0.17, -0.69, -2.41, -2.16, -0.8, -0.86, 
                 -0.96, -0.8, -0.81, -1.96, -1.86, -0.37, -0.49, -1.11, -0.79, 
                 -1.07, -1.74, -2.44, -3.3, -2.22, -1.1, -0.44, -1.04, -2.79, 
                 -2.93, -2.8, -2.75, -0.59, -0.92, -1.38, -2.51, -2.2, -2.04, 
                 -1.32, -0.4, -1.18, -1.22, -2.91, -2.32, -2.4, -1.81, -0.74, 
                 -1.52, -1.46, -0.78, -1.77, -1.96, -2.13, -1.29, -1.53, -0.93, 
                 -0.58, -1.63, -2.23, -2.48, -1.63, -1.69, -1.09, -1.97, -0.6, 
                 -0.65, -1.04, -0.44, -1.28, -1.29, -1.65, -0.35, -0.61, -1.26, 
                 -0.58, -1.25, -1.71, -2.67, -0.73, -2.44, -1.12, -0.26, 0.36, 
                 -0.26, -3.1, -1.05, -2.26, -1.04, -0.23, 0.34, -0.5, -1.41, -0.77, 
                 -0.83, -0.6, 0.01, -0.56, 0.02, -1.23, -1.09, -0.8, 0.08, 0.12, 
                 -0.46, 0.59, -1.56, -1.59, -1.67, -1.58, -2.71, -1.54, -0.76, 
                 -2.2, -2.04, -2.11, -2.52, -2.97, -1.94, -1.42, 0.49, -1.01, 
                 -0.48, 0.2, -0.55, -0.58, -0.28, -0.15, -0.79, -0.17, 0.21, 0.17, 
                 0.27, -0.54, -1.54, -1.37, -1.03, 0.01, 0.17, 0.71, -0.24, -1.6, 
                 -1.18, -0.21, 0.8, 0.68, 0.82, -0.13, -1.37, -1.68, -1.76, -1.81, 
                 -3.44, -1.53, -0.43, -1.51, -2.39, -2.61, -2.28, -3.14, -1.48, 
                 -0.86, -1.47, -0.92, 0.04, -0.17, -0.95, -0.57, -0.37, -0.97, 
                 -0.54, -0.09, -0.14, -0.64, 0.35, -0.14, -2.32, -1.28, -1.3, 
                 -0.38, 0.75, -0.91, -1.3, -2.35, -0.6, -1.18, -0.27, 0.21, -1.25, 
                 -1.28, 0.66, -0.12, -0.71, -1.74, -1.08, -1.29, -1.61, 0.38, 
                 -0.71, -1.26, -1.69, -1.7, -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"
)

在此处输入图像描述

于 2021-01-18T00:44:22.293 回答
2

您可以使用带有参数hist3D的包:plot3Dz

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.25, -2.01, -1.69, 
-1.17, -1.42, -1.46, -0.82, -0.83, -1.98, -1.81, -2.21, -2.39, 
-1.74, -2.11, -0.81, -2.25, -1.96, -2.76, -2.28, -2.32, -2.44, 
-0.62, -1.19, -2.37, -1.29, -1.2, 0.09, -0.38, -1, -1.84, -2.1, 
-0.87, -0.49, -0.57, -0.75, -1.25, -2.44, -1.08, -1.37, -1.66, 
-1.12, -1.12, -1.2, -2.29, -1.7, -1.96, -1.58, -0.63, -0.86, 
-2.68, -2.13, -1.18, -0.89, -0.14, -0.37, -0.57, -2.9, -2.51, 
-1.26, -0.22, -0.34, -0.17, -0.69, -2.41, -2.16, -0.8, -0.86, 
-0.96, -0.8, -0.81, -1.96, -1.86, -0.37, -0.49, -1.11, -0.79, 
-1.07, -1.74, -2.44, -3.3, -2.22, -1.1, -0.44, -1.04, -2.79, 
-2.93, -2.8, -2.75, -0.59, -0.92, -1.38, -2.51, -2.2, -2.04, 
-1.32, -0.4, -1.18, -1.22, -2.91, -2.32, -2.4, -1.81, -0.74, 
-1.52, -1.46, -0.78, -1.77, -1.96, -2.13, -1.29, -1.53, -0.93, 
-0.58, -1.63, -2.23, -2.48, -1.63, -1.69, -1.09, -1.97, -0.6, 
-0.65, -1.04, -0.44, -1.28, -1.29, -1.65, -0.35, -0.61, -1.26, 
-0.58, -1.25, -1.71, -2.67, -0.73, -2.44, -1.12, -0.26, 0.36, 
-0.26, -3.1, -1.05, -2.26, -1.04, -0.23, 0.34, -0.5, -1.41, -0.77, 
-0.83, -0.6, 0.01, -0.56, 0.02, -1.23, -1.09, -0.8, 0.08, 0.12, 
-0.46, 0.59, -1.56, -1.59, -1.67, -1.58, -2.71, -1.54, -0.76, 
-2.2, -2.04, -2.11, -2.52, -2.97, -1.94, -1.42, 0.49, -1.01, 
-0.48, 0.2, -0.55, -0.58, -0.28, -0.15, -0.79, -0.17, 0.21, 0.17, 
0.27, -0.54, -1.54, -1.37, -1.03, 0.01, 0.17, 0.71, -0.24, -1.6, 
-1.18, -0.21, 0.8, 0.68, 0.82, -0.13, -1.37, -1.68, -1.76, -1.81, 
-3.44, -1.53, -0.43, -1.51, -2.39, -2.61, -2.28, -3.14, -1.48, 
-0.86, -1.47, -0.92, 0.04, -0.17, -0.95, -0.57, -0.37, -0.97, 
-0.54, -0.09, -0.14, -0.64, 0.35, -0.14, -2.32, -1.28, -1.3, 
-0.38, 0.75, -0.91, -1.3, -2.35, -0.6, -1.18, -0.27, 0.21, -1.25, 
-1.28, 0.66, -0.12, -0.71, -1.74, -1.08, -1.29, -1.61, 0.38, 
-0.71, -1.26, -1.69, -1.7, -1.89, -1.84), .Dim = c(14L, 22L))

plot3D::hist3D(z=m)

在此处输入图像描述

于 2021-01-17T20:13:08.610 回答