简体   繁体   English

我怎么能在 R 中的 plot 一个 3d 直方图?

[英]How i can plot a 3d histogram in R?

I have a table with numbers and can plot a 3d histogram in excel.我有一个带有数字的表格,可以在 excel 中的 plot 和 3d 直方图。 Here is my histogram in excel:这是我在 excel 中的直方图:

在此处输入图像描述

How can i do the same in R with plot3d?我如何在 R 中使用 plot3d 做同样的事情? In their example they are use 3 digits for x, y, z.在他们的示例中,他们使用 3 位数字表示 x、y、z。 Here their dataset and histogram in R:这是他们在 R 中的数据集和直方图:

在此处输入图像描述

But i have only one digit for one bar My table:但我的一个酒吧只有一位数字我的桌子:

-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: I tried to insert a full dataset to one of examples. UPD:我尝试将完整的数据集插入其中一个示例。 Just want to see how plot3 handle with a huge amount of bars.只是想看看 plot3 如何处理大量条形图。 Its pretty stucking.它很卡。 And i dont see a negative bars.而且我没有看到负面的酒吧。 I assume that positive bar will apperars upper 0 and negative bottom, like on my first picture.我假设正条将出现在上 0 和负底部,就像我的第一张照片一样。

So, i realize that firstly i need to render a big amount of data to be able to choose a right library.所以,我意识到首先我需要渲染大量数据才能选择正确的库。 Also i assume, that full realtime 3d rendering maybe impossible for that amount of data.我还假设,对于这么多的数据,完全实时的 3d 渲染可能是不可能的。 So it will be normal if library will render just a 1 picture like a hist3d does.因此,如果库像 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"
            )

Help me please to plot a histogram from a full txt file with positive up bars and negative down.请帮助我 plot 来自完整 txt 文件的直方图,带有正向上条和负向下。

My full txt file is here https://pastebin.com/2zyyRDy8我的完整 txt 文件在这里https://pastebin.com/2zyyRDy8

I've read my txt file to res_cut, but i see data structure different from your examples, in my there 700 objs of 23 variable我已将我的 txt 文件读到 res_cut,但我看到的数据结构与您的示例不同,在我那里有 700 个 objs 的 23 个变量

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

读分隔符

With the graph3d package:使用graph3d package:

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

在此处输入图像描述

You could use hist3D from plot3D package with z parameter:您可以使用带有z参数的hist3D plot3D中的 hist3D :

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)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM