R水彩画图

时间:2018-10-17 19:25:23

标签: r ggplot2 plot plotly

我正在处理一个相当大的数据集(2000列11行)。其中一个子集是我在下面的内容

     Col1      Col2       Col3      Col4       Col5      Col6         Col7        Col8      Col9       Col10
1  2509.60840 650.44520 1208.00000 1795.00000 2889.000000 2158.00000 1827.25070 1482.000000 1858.00000 2544.39450
2    58.03994 -23.13326  -15.49636   12.09075   86.300341   34.46581   13.94546   -4.533958   15.89606   60.50394
3    94.15235  48.95360   80.27238  120.64317   62.791467  309.90168  175.94835  175.427179   83.94264  173.50097
4   245.69264  55.18302  137.75501  200.89969  -26.608255  161.46379  237.20321   84.304826  178.47248   97.40814
5    48.63110  70.49905  111.77759  181.52456 -107.426908  278.38505  116.95109  151.338578  218.93919   57.89194
6   264.90391  71.18622  129.02855  116.35842  -49.956152  147.17100  147.19528  229.756718   98.92684  193.43460
7   208.02697  75.31583   70.26002  136.39284    4.383722  150.74978  156.59314  162.983479   87.34028  358.01097
8   168.77588  71.57783  156.26653  132.90093   46.189138  254.28341  131.49356  211.540117   69.87448  312.34010
9   212.42247  53.04903  165.36475   49.42609  -14.050163   75.35783  160.37957  150.106290   96.19735  170.49562
10  175.34079  56.51675  148.31084  150.04976   32.373020  120.79866  147.48743  126.595648   84.46121  142.00257
11  249.20497  60.53568  139.56612  145.09104    6.308908  127.05724  141.34019  134.092717  103.45419  294.44998
12   67.80644  46.36427  101.25284  128.60477  -33.661878  361.66227   81.30154   88.232663  138.95064   83.37984

如何从该数据集中创建瀑布线图?看起来像这样的https://andrewgelman.com/2012/08/26/graphs-showing-regression-uncertainty-the-code/

请注意,第一行{2509.60840 650.44520 1208.00000 1795.00000 2889.000000 2158.00000 1827.25070 1482.000000 1858.00000 2544.39450}中的值为我的x值,其余为与每个x值相对应的y值。例如。

{58.03994, 94.15235, 245.69264, 48.63110,264.90391.....67.80644}是我与y相关的x=2509.60840值,依此类推。

1 个答案:

答案 0 :(得分:1)

here获得vwReg代码

将数据框更改为可行的

library(tidyverse)
    structure(list(Col1 = c(2509.6084, 58.03994, 94.15235, 245.69264, 
48.6311, 264.90391, 208.02697, 168.77588, 212.42247, 175.34079, 
249.20497, 67.80644), Col2 = c(650.4452, -23.13326, 48.9536, 
55.18302, 70.49905, 71.18622, 75.31583, 71.57783, 53.04903, 56.51675, 
60.53568, 46.36427), Col3 = c(1208, -15.49636, 80.27238, 137.75501, 
111.77759, 129.02855, 70.26002, 156.26653, 165.36475, 148.31084, 
139.56612, 101.25284), Col4 = c(1795, 12.09075, 120.64317, 200.89969, 
181.52456, 116.35842, 136.39284, 132.90093, 49.42609, 150.04976, 
145.09104, 128.60477), Col5 = c(2889, 86.300341, 62.791467, -26.608255, 
-107.426908, -49.956152, 4.383722, 46.189138, -14.050163, 32.37302, 
6.308908, -33.661878), Col6 = c(2158, 34.46581, 309.90168, 161.46379, 
278.38505, 147.171, 150.74978, 254.28341, 75.35783, 120.79866, 
127.05724, 361.66227), Col7 = c(1827.2507, 13.94546, 175.94835, 
237.20321, 116.95109, 147.19528, 156.59314, 131.49356, 160.37957, 
147.48743, 141.34019, 81.30154), Col8 = c(1482, -4.533958, 175.427179, 
84.304826, 151.338578, 229.756718, 162.983479, 211.540117, 150.10629, 
126.595648, 134.092717, 88.232663), Col9 = c(1858, 15.89606, 
83.94264, 178.47248, 218.93919, 98.92684, 87.34028, 69.87448, 
96.19735, 84.46121, 103.45419, 138.95064), Col10 = c(2544.3945, 
60.50394, 173.50097, 97.40814, 57.89194, 193.4346, 358.01097, 
312.3401, 170.49562, 142.00257, 294.44998, 83.37984)), class = "data.frame", row.names = c(NA, 
-12L)) -> df

t(df) %>% 
  data.frame() %>% 
  gather(variable, y, -X1) -> new_df

创造你的身材

vwReg(y ~ X1, new_df)