@FJCC, Thank you so much for explaining this. This definitely is very clear now!
I was trying to implement this into my data. However, I am still running into issues here. I think it would work fine if I had only Brands as one of the variables. However, I have several variables instead which we need for filtering the visualizations. For example, for USA, product GYC, Wave 1, in 2020. So, we do need these extra variables also. I think I am making mistakes with grouping because of several variables.
Data is huge with 12700 rows or so for last 6 years. I have tried to create a reprex for better understanding covering last two years. This is also big for reprex I believe, but I think it covers all the components.
I am still looking to create the chart the way you have created with Brands on X-axis and values as Percentages for Orange bar and Diff for Grey bar.
Do you think this can still work with this kind of data?
Thanks again for your help!
data <- data.frame(
stringsAsFactors = FALSE,
Date = c("2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2020/01/01 00:00:00","2020/01/01 00:00:00",
"2020/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00",
"2019/01/01 00:00:00","2019/01/01 00:00:00"),
Wave = c("Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 2",
"Wave 2","Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1","Wave 1","Wave 2","Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 2",
"Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1","Wave 1","Wave 2","Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 2",
"Wave 1","Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1","Wave 2","Wave 2","Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 2",
"Wave 2","Wave 2","Wave 2","Wave 2","Wave 1",
"Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1","Wave 1","Wave 1","Wave 1",
"Wave 1","Wave 1"),
Brands = c("Brand 1",
"Brand 1","Brand 1","Brand 1","Brand 2","Brand 2",
"Brand 2","Brand 2","Brand 3","Brand 3",
"Brand 3","Brand 3","Brand 1","Brand 1",
"Brand 1","Brand 1","Brand 2","Brand 2","Brand 2",
"Brand 2","Brand 3","Brand 3","Brand 3",
"Brand 3","Brand 1","Brand 1","Brand 1","Brand 1",
"Brand 2","Brand 2","Brand 2","Brand 2",
"Brand 3","Brand 3","Brand 3","Brand 3","Brand 1",
"Brand 1","Brand 1","Brand 1","Brand 2",
"Brand 2","Brand 2","Brand 2","Brand 3","Brand 3",
"Brand 3","Brand 3","Brand 1","Brand 1",
"Brand 1","Brand 1","Brand 2","Brand 2","Brand 2",
"Brand 2","Brand 3","Brand 3","Brand 3",
"Brand 3","Brand 1","Brand 1","Brand 1",
"Brand 1","Brand 2","Brand 2","Brand 2","Brand 2",
"Brand 3","Brand 3","Brand 3","Brand 3",
"Brand 1","Brand 1","Brand 1","Brand 1","Brand 2",
"Brand 2","Brand 2","Brand 2","Brand 3",
"Brand 3","Brand 3","Brand 3","Brand 1","Brand 1",
"Brand 1","Brand 1","Brand 2","Brand 2",
"Brand 2","Brand 2","Brand 3","Brand 3","Brand 3",
"Brand 3"),
LocationID = c("US1","US1",
"US1","US1","US1","US1","US1","US1","US1",
"US1","US1","US1","US1","US1","US1","US1",
"US1","US1","US1","US1","US1","US1","US1",
"US1","US1","US1","US1","US1","US1","US1",
"US1","US1","US1","US1","US1","US1","US1",
"US1","US1","US1","US1","US1","US1","US1",
"US1","US1","US1","US1","CA1","CA1","CA1",
"CA1","CA1","CA1","CA1","CA1","CA1","CA1",
"CA1","CA1","CA1","CA1","CA1","CA1","CA1",
"CA1","CA1","CA1","CA1","CA1","CA1","CA1",
"CA1","CA1","CA1","CA1","CA1","CA1","CA1",
"CA1","CA1","CA1","CA1","CA1","CA1","CA1",
"CA1","CA1","CA1","CA1","CA1","CA1","CA1",
"CA1","CA1","CA1"),
Tiers = c("Tier 1",
"Tier 1","Tier 2","Tier 2","Tier 1","Tier 2",
"Tier 1","Tier 2","Tier 1","Tier 1","Tier 2",
"Tier 2","Tier 1","Tier 1","Tier 2","Tier 2",
"Tier 1","Tier 2","Tier 1","Tier 2","Tier 1",
"Tier 1","Tier 2","Tier 2","Tier 1","Tier 1",
"Tier 2","Tier 2","Tier 1","Tier 2","Tier 1",
"Tier 2","Tier 1","Tier 1","Tier 2","Tier 2",
"Tier 1","Tier 1","Tier 2","Tier 2",
"Tier 1","Tier 2","Tier 1","Tier 2","Tier 1",
"Tier 1","Tier 2","Tier 2","Tier 1","Tier 1",
"Tier 2","Tier 2","Tier 1","Tier 1","Tier 2",
"Tier 2","Tier 1","Tier 1","Tier 2","Tier 2",
"Tier 1","Tier 1","Tier 2","Tier 2","Tier 1",
"Tier 1","Tier 2","Tier 2","Tier 1","Tier 1",
"Tier 2","Tier 2","Tier 1","Tier 1","Tier 2",
"Tier 2","Tier 1","Tier 1","Tier 2","Tier 2",
"Tier 1","Tier 1","Tier 2","Tier 2","Tier 1",
"Tier 1","Tier 2","Tier 2","Tier 1",
"Tier 1","Tier 2","Tier 2","Tier 1","Tier 1",
"Tier 2","Tier 2"),
Product = c("GYC","MCH",
"FSN","CPR","GYC","FSN","MCH","CPR","GYC",
"MCH","FSN","CPR","GYC","MCH","FSN","CPR",
"GYC","FSN","MCH","CPR","GYC","MCH","FSN",
"CPR","GYC","MCH","FSN","CPR","GYC","FSN",
"MCH","CPR","GYC","MCH","FSN","CPR","GYC",
"MCH","FSN","CPR","GYC","FSN","MCH","CPR",
"GYC","MCH","FSN","CPR","MCH","GYC","FSN",
"CPR","MCH","GYC","FSN","CPR","MCH","GYC",
"FSN","CPR","MCH","GYC","FSN","CPR","MCH",
"GYC","FSN","CPR","MCH","GYC","FSN","CPR",
"MCH","GYC","FSN","CPR","MCH","GYC","FSN",
"CPR","MCH","GYC","FSN","CPR","MCH","GYC",
"FSN","CPR","MCH","GYC","FSN","CPR","MCH",
"GYC","FSN","CPR"),
Volume = c(227434228.7,
227434228.7,227434228.7,227434228.7,227434228.7,
227434228.7,227434228.7,227434228.7,
227434228.7,227434228.7,227434228.7,227434228.7,
227434228.7,227434228.7,227434228.7,227434228.7,
227434228.7,227434228.7,227434228.7,227434228.7,
227434228.7,227434228.7,227434228.7,
227434228.7,255116000,255116000,255116000,255116000,
255116000,255116000,255116000,255116000,
255116000,255116000,255116000,255116000,255116000,
255116000,255116000,255116000,255116000,
255116000,255116000,255116000,255116000,255116000,
255116000,255116000,18533000,18533000,
18533000,18533000,18533000,18533000,18533000,
18533000,18533000,18533000,18533000,18533000,
18533000,18533000,18533000,18533000,18533000,
18533000,18533000,18533000,18533000,18533000,
18533000,18533000,22903662,22903662,22903662,
22903662,22903662,22903662,22903662,22903662,
22903662,22903662,22903662,22903662,22903662,
22903662,22903662,22903662,22903662,22903662,
22903662,22903662,22903662,22903662,22903662,
22903662),
WeightedAvg = c(165117250,
125316260,111442772.1,47533753.79,219246596.4,
216517385.7,212196135.4,145557906.4,173759750.7,
172850013.8,149651722.5,82786059.24,
143738432.5,131229549.9,105756916.3,45486845.74,
214015609.2,212651003.8,211286398.4,139417182.2,
178535869.5,167164158.1,152608367.4,79374545.81,
173223764,144905888,122455680,44645300,
245676708,242870432,241849968,156641224,207154192,
195418856,184193752,85208744,169652140,
139038220,130874508,44390184,244401128,241594852,
238788576,160212848,204603032,196694436,
170162372,83933164,12750704,12157648,5671098,
1983031,17680482,17550751,16068111,8488114,
15178527,13640288,9525962,3817798,11935252,10526744,
6115890,1501173,17402487,17254223,15938380,
7431733,14233344,12991633,9414764,3354473,
15826430.44,13879619.17,7168846.206,2381980.848,
21758478.9,21621056.93,20040704.25,
9871478.322,18322929.6,16925806.22,11887000.58,
4855576.344,15963852.41,13467353.26,7649823.108,
2588113.806,22216552.14,22056226.51,20659103.12,
9734056.35,18345833.26,17292264.81,11818289.59,
4191370.146),
Percentage = c(0.726,0.551,
0.49,0.209,0.964,0.952,0.933,0.64,0.764,
0.76,0.658,0.364,0.632,0.577,0.465,0.2,0.941,
0.935,0.929,0.613,0.785,0.735,0.671,0.349,
0.679,0.568,0.48,0.175,0.963,0.952,0.948,
0.614,0.812,0.766,0.722,0.334,0.665,0.545,
0.513,0.174,0.958,0.947,0.936,0.628,0.802,
0.771,0.667,0.329,0.688,0.656,0.306,0.107,
0.954,0.947,0.867,0.458,0.819,0.736,0.514,
0.206,0.644,0.568,0.33,0.081,0.939,0.931,
0.86,0.401,0.768,0.701,0.508,0.181,0.691,
0.606,0.313,0.104,0.95,0.944,0.875,0.431,0.8,
0.739,0.519,0.212,0.697,0.588,0.334,0.113,
0.97,0.963,0.902,0.425,0.801,0.755,0.516,
0.183),
Lag = c(NA,0.726,
0.551,0.221,NA,0.964,0.952,0.658,NA,0.764,
0.76,0.339,0.001,0.632,0.577,0.206,0.029,
0.941,0.935,0.648,0.014,0.785,0.735,0.338,
0.001,0.679,0.568,0.205,0.035,0.963,0.952,
0.652,0.022,0.812,0.766,0.355,NA,0.665,0.545,
0.223,0.046,0.958,0.947,0.69,0.016,0.802,
0.771,0.335,0.001,0.688,0.356,0.115,0.043,
0.954,0.896,0.448,0.026,0.819,0.662,0.207,
NA,0.644,0.303,0.114,0.017,0.939,0.877,
0.435,0.007,0.768,0.602,0.208,NA,0.691,0.328,
0.107,0.016,0.95,0.9,0.457,0.008,0.8,0.65,
0.196,NA,0.697,0.341,0.109,0.024,0.97,
0.912,0.432,0.009,0.801,0.633,0.229),
Diff = c(NA,-0.175,
-0.061,-0.012,NA,-0.012,-0.019,-0.018,NA,
-0.004,-0.102,0.025,0.631,-0.055,-0.112,-0.006,
0.912,-0.006,-0.006,-0.035,0.771,-0.05,
-0.064,0.011,0.678,-0.111,-0.088,-0.03,0.928,
-0.011,-0.004,-0.038,0.79,-0.046,-0.044,
-0.021,NA,-0.12,-0.032,-0.049,0.912,-0.011,
-0.011,-0.062,0.786,-0.031,-0.104,-0.006,
0.687,-0.032,-0.05,-0.008,0.911,-0.007,-0.029,
0.01,0.793,-0.083,-0.148,-0.001,NA,-0.076,
0.027,-0.033,0.922,-0.008,-0.017,-0.034,
0.761,-0.067,-0.094,-0.027,NA,-0.085,-0.015,
-0.003,0.934,-0.006,-0.025,-0.026,0.792,
-0.061,-0.131,0.016,NA,-0.109,-0.007,0.004,
0.946,-0.007,-0.01,-0.007,0.792,-0.046,-0.117,
-0.046)
)