How do I build histogram for a data set with multiple factors; one plot per combination?

Viewed 27

I am trying to make histograms for a data containing 2 factors (with 3 - L, M, H and 2 values - A, B respectively; so 6 total combinations); I have been able to extract the factors as

str_split(facCols, '\\ ') 

str_split(facCols, '\\ ') = 
[[1]]
[1] "var_Structure"

[[2]]
[1] "var_Completion"

If I do

plt <- ggplot(dF) +
               geom_bar(aes_string(x = as.name(varName),
                                         y = yType, fill = "var_Structure"),
                              bins = input$numBins,
                              stat = statTypeToUse) +
               ylab(yLabel);

I get histogram with 3 factors of var_Structure as 3 colours; so 3 histograms stacked on top of each other like this - enter image description here; I will be able to replace fill with a variable if necessary


How do I generate multiple histograms branched by factors - i.e. in the above example; we see 2 factors var_Structure and var_Completion; var_Structure has 3 categories and the other has 2; hence 6 categories.

  • I need the code for that

.


So I want histograms by either var_Structure or var_Completion or both for any selected feature (there are several features in the data).

Example; for box plots (the code structure for box plots is somewhat different hence not replicated to histogram.R yet); the attached image is for 1 combination (I ignored the number of plots and plots per row for now)-

Thanksenter image description here

If I add "facet_wrap(~var_Structure)" to the plt equation above; I get 3 histograms stacked side by side for each value (L, M and H) as -enter image description here

The value of dput(dF) is (first few lines shown):

Browse[1]> a
    var_Permeability_Lower_Reservoir var_Base_Porosity var_Gas_Cap_Multiplier var_Structure var_Completion
1                          263.27417         0.1669688              1.0100129             H              A
2                          267.50195         0.1611080              1.3186007             M              B
3                          263.06475         0.1818014              1.0764338             M              A
4                          218.13742         0.1676185              1.0267698             M              A
5                          196.45038         0.1360371              1.0938945             H              A
6                          178.61395         0.1403386              0.8029133             L              A
7                          196.29901         0.1503646              0.7968232             M              A
8                          177.79836         0.1291919              0.7553550             L              B
9                          215.95496         0.1554152              1.1445756             M              B
10                         191.89015         0.1579022              1.0872317             H              A
11                         236.36186         0.1616644              0.8672707             L              A
12                         181.85593         0.1460313              1.0099307             M              B
13                         154.47429         0.1642192              0.8909194             L              A
14                         193.90676         0.1642116              0.8715086             H              B
15                         205.14902         0.1415833              1.1801834             L              A
16                         154.25318         0.1201707              0.9758134             L              B
17                         168.64365         0.1529790              0.8592213             M              B
18                         305.38618         0.1929035              1.1191320             M              A
19                         136.50078         0.1485920              0.8710400             M              A
20                         178.73742         0.1475503              0.9295012             M              A
21                         179.70423         0.1279999              1.1102626             H              A
22                         233.21890         0.1647360              1.2486242             H              A
23                          84.71453         0.1300761              0.7029356             L              A
24                         212.21649         0.1467533              1.1500688             M              B
25                         163.56754         0.1386917              0.7135034             L              A
26                         214.18458         0.1596420              1.1724244             M              B
27                         163.70115         0.1416607              0.8062734             M              A
28                         193.73708         0.1293809              1.1411449             H              B
29                         194.96001         0.1169663              0.9131467             H              B
30                         175.26654         0.1483365              1.1595410             L              A
31                         197.27612         0.1498132              0.9814747             M              B
32                         205.13548         0.1540031              0.9470645             M              B
33                         229.97650         0.1702260              0.8859179             L              B
34                         212.73503         0.1381706              1.1055204             L              B
35                         124.83404         0.1356520              0.9252043             M              B
36                          85.17525         0.1028928              0.8516953             L              A
37                         234.36754         0.1634207              1.1982017             M              A
38                         255.39749         0.1652418              0.8248917             L              A
39                         141.19723         0.1373028              1.1561689             H              B
40                          71.73414         0.1143752              1.0268035             L              B
41                         183.12494         0.1568062              1.0373725             H              A
42                         177.96733         0.1363584              1.2217063             L              B
43                         261.47087         0.1638147              0.9567899             L              A
44                         205.95538         0.1363368              1.0375563             M              B
45                         198.55246         0.1167239              0.8407450             M              A
46                         295.13872         0.1941632              0.9791860             M              A
47                         138.87225         0.1148474              1.2467456             H              B
48                         184.77362         0.1190078              1.0310348             M              B
49                         368.07339         0.1823696              1.0106700             L              A
50                         206.13989         0.1879791              0.9893809             H              A
51                         253.94104         0.1629845              1.1326787             M              A
52                         215.92349         0.1643784              0.9166538             L              A
53                         246.21162         0.1709007              1.1649138             L              B
54                         247.17818         0.1826742              0.7454191             L              A
55                         227.04735         0.1470442              1.1121175             H              A
56                         114.07020         0.1086669              0.9701277             M              A
57                         210.69963         0.1758344              1.0805445             H              A
58                         199.72016         0.1423903              1.1089380             L              A
59                         229.55268         0.1327365              0.9858005             L              B
60                         150.90605         0.1403100              1.0352196             H              A
61                         281.02128         0.1846430              0.9715969             L              A
62                         207.40988         0.1377969              1.1366674             M              B
63                         156.91522         0.1302711              0.8580335             M              A
64                         204.35576         0.1411931              1.0777615             M              B
65                         217.13459         0.1623327              1.0506816             L              A
66                         172.46038         0.1256495              1.0728593             M              B
67                         181.65780         0.1464037              0.8091950             H              A
68                         313.81243         0.1932871              1.2498429             M              A
69                         172.53337         0.1394672              0.6307879             L              A
70                         191.18261         0.1392919              1.1613922             M              A
71                         241.23054         0.1608343              1.2457776             L              B
72                         116.05424         0.1168858              1.1305477             H              B
73                         182.38260         0.1282228              1.0070034             H              A
74                         201.51206         0.1534617              0.9117973             L              A
75                         202.68809         0.1485116              1.0525287             H              A
76                         196.27562         0.1322705              1.0723585             M              B
77                         204.49501         0.1468262              0.7881554             L              A
78                         134.63001         0.1213143              1.1169956             H              B
79                         211.95177         0.1493203              0.8702907             L              B
80                         171.38714         0.1467921              0.9197116             L              A
81                         170.94278         0.1332998              1.2216489             H              B
82                         228.67989         0.1424839              0.9737087             L              B
83                         168.28298         0.1449063              1.1152528             H              B
84                         144.32628         0.1505579              1.2021320             H              B
85                         158.94027         0.1408800              0.9819064             H              B
86                         156.08219         0.1333568              1.0581466             H              A
87                         166.71493         0.1458638              1.1151675             H              B
88                         147.87526         0.1280399              1.0095173             L              B
89                         181.94520         0.1166357              1.0735045             L              B
90                         218.11285         0.1372276              0.8282802             L              A
91                         154.88788         0.1278726              1.0922211             H              B
92                         210.41620         0.1169160              1.2250916             H              A
93                         184.68110         0.1446212              0.8947389             M              B
94                         247.22873         0.1881481              1.1726561             H              A
95                         123.03210         0.1204326              0.8615222             M              B
96                         273.89845         0.1866098              0.8986147             L              A
97                         283.69576         0.1663502              0.7153828             L              A
98                         187.82404         0.1444420              1.0397109             L              B
99                         265.23879         0.1593231              1.1783723             L              B
100                        172.13899         0.1453102              1.0810726             H              B
101                        240.26457         0.1664885              1.3015581             M              B
102                        228.82647         0.1532083              1.1086491             L              B
103                        192.23107         0.1417528              0.9532704             L              B
104                        156.60953         0.1306341              1.1166758             M              A
105                        183.69727         0.1462923              1.0401088             L              B
106                        276.31094         0.1772548              1.0470672             L              A
107                        223.55592         0.1872168              0.9810797             M              A
108                        158.41122         0.1678087              1.0257392             M              A
109                        203.14775         0.1450536              0.9292287             L              B
110                        174.23055         0.1134264              1.1842942             H              A
111                        202.36083         0.1517960              1.1529147             M              B
112                        163.60085         0.1428539              0.9022129             M              A
113                        208.02290         0.1596664              1.1808731             H              A
114                        199.95970         0.1574619              1.0869926             H              A
115                        197.95316         0.1575470              0.8367736             L              A
116                        165.41576         0.1322471              0.8799627             M              B
117                        198.63301         0.1648095              1.1422483             H              B
118                        240.59179         0.1445066              1.1278004             H              B
119                         99.12894         0.1446183              0.8718171             L              B
120                        209.13064         0.1494909              1.1222046             L              B
121                        129.76283         0.1362108              1.0241713             M              A
122                        147.84956         0.1481275              1.0262096             H              A
123                        229.62705         0.1797307              1.0847134             M              A
124                        232.03556         0.1597711              1.0018033             L              B
125                        205.12524         0.1587949              1.2302559             H              A
           UR Plateau_Length Water_Breakthrough_Time
1   13.554425       20.95136                23.93151
2   17.936323       17.48954                26.34339
3   15.345938       20.73977                22.65381
4   14.952172       19.03083                22.03940
5   18.270992       19.55592                27.17748
6   13.788032       20.85793                24.36336
7   14.326892       21.27976                22.51072
8   12.473983       21.54425                23.83292
9   16.212341       18.60977                26.38999
10  19.243779       18.47641                22.95120
11  11.854447       21.58850                21.69424
12  17.358584       19.53614                24.19299
13  15.878039       20.00372                22.61399
14  16.183803       20.71725                23.65273
15  16.147741       18.91117                25.42375
16  15.001292       18.89476                27.26762
17  15.145592       20.21179                23.56487
18  14.432121       21.41568                22.96534
19  14.196965       18.41061                23.17488
20  16.135973       20.63341                24.07252
21  18.006102       17.62823                28.90577
22  18.055910       17.63154                26.27387
23   7.856546       20.65880                22.32396
24  15.897017       18.97140                28.07061
25  12.042129       21.48231                22.14560
26  16.876552       19.30640                24.88540
27  13.648775       22.25498                22.51153
28  18.671410       19.70770                28.17226
29  14.478232       21.66519                26.41224
30  19.736013       17.82324                28.12048
31  17.197828       20.29194                24.29617
32  13.111844       18.86112                23.81461
33  12.702122       20.93153                23.17450
34  14.765173       20.01417                27.06341
35  13.914308       18.04402                26.18503
36   8.862773       18.82256                27.94096
37  17.175880       18.77850                27.80196
38  10.844508       23.35491                21.78498
39  18.277627       18.86724                28.65014
40  11.203586       15.99210                31.05158
41  18.341139       20.22864                25.84770
42  20.150185       16.75949                29.79935
43  12.629301       21.75755                21.82355
44  13.645343       19.83293                28.31793
45  13.337338       22.71906                27.05810
46  12.916238       21.55443                19.41141
47  18.492077       15.99644                31.63226
48  16.367677       19.33926                27.94793
49   7.061263       23.08732                22.78485
50  15.471065       18.78868                20.96853
51  15.607662       19.06178                24.23650
52  13.085403       21.61737                21.78696
53  16.741375       18.45258                26.60718
54  10.722375       22.95274                20.33985
55  15.141526       20.23248                23.85777
56  12.749559       20.82925                28.81001
57  16.270872       17.67392                23.27721
58  18.828400       18.36512                28.46007
59  12.402071       19.80917                27.94420
60  16.844923       19.52384                25.98256
61  13.067255       21.74576                20.23754
62  15.267266       20.58411                28.07406
63  13.729644       20.25977                25.39636
64  14.523803       18.87236                27.22556
65  15.073595       20.87433                24.20782
66  17.197886       18.14095                29.33863
67  14.226104       21.62080                22.67292
68  15.947651       20.14295                23.20163
69  10.955223       24.40030                21.70395
70  19.473022       17.05457                27.96293
71  17.637229       19.31753                27.50994
72  15.778121       16.42994                30.28424
73  16.427891       18.72037                27.94671
74  12.538768       20.08270                22.18071
75  14.497429       18.76090                24.36143
76  17.744448       18.93281                28.30062
77  10.262050       19.82381                22.33345
78  16.619049       17.96422                28.71089
79  11.638417       20.93100                24.89559
80  15.834516       19.92008                22.06323
81  19.888687       17.04019                29.22954
82  12.715006       22.07076                26.30152
83  18.751492       17.19978                27.01642
84  19.768862       17.89450                28.18151
85  16.254397       19.33980                25.80807
86  17.001352       18.00091                26.28048
87  18.767452       18.38079                25.54249
88  15.736196       18.83252                27.07411
89  16.887054       18.87111                30.22052
90  10.319194       23.22482                24.27691
91  17.229768       16.97782                27.87811
92  15.594251       19.03617                30.73006
93  15.509433       21.39634                26.00926
94  17.696689       17.88590                22.44437
95  12.072117       20.00560                27.35905
96  12.351771       22.00023                21.71173
97   8.001236       24.26914                22.18162
98  17.800568       21.00244                26.47033
99  15.737441       19.72344                27.23454
100 18.304420       17.49891                26.45270
101 18.818583       17.35857                25.82779
102 15.365499       19.90544                25.23185
103 16.336486       21.10933                25.07658
104 17.797173       16.63165                28.64003
105 17.864066       18.89982                26.37632
106 14.104073       21.34321                22.15787
107 15.147574       21.01098                20.97346
108 18.275315       19.23355                21.97037
109 12.389522       20.91476                25.68265
110 18.363116       19.49522                30.67966
111 16.236894       18.63887                26.53288
112 15.211241       22.50959                23.59817
113 17.051357       18.71352                25.98363
114 19.237745       19.40473                26.08793
115 15.315565       22.22898                21.28649
116 14.370516       19.58891                26.79750
117 20.471355       17.99187                25.75849
118 14.985823       19.98728                27.68947
119 12.167622       19.71098                23.60384
120 15.616555       16.96992                25.38420
121 15.709737       19.61119                26.54546
122 17.001622       18.91564                24.10441
123 16.302102       20.01465                23.22498
124 13.958958       20.23385                26.17420
125 17.793882       17.11729                25.03506
0 Answers
Related