
%% Stacked Bar Graphs for Electriv Vehicle

clear all
clc

%--------------------------------------------------------------------------
%% All datasets

%--------------------------------------------------------------------------
%                       April, 2021
%--------------------------------------------------------------------------

EVInfo1Apr21   = [22.80 30.21; 32.46 14.53];      % EVInfo1 (Little or nothing at all)
EVInfo2Apr21   = [20.19 17.75; 27.51 34.56];      % EVInfo2 (Read or heard a lot)

Env1Apr21   = [49.10 31.72; 15.06 4.12];          % IAM: Income above sample mean
Env2Apr21   = [11.14 23.07; 36.67 29.12];         % IBM: Income below sample mean

NotEVOwnerApr21 = [23.60 26.98; 30.65 18.77];  
EVOwnerApr21    = [4.62 11.26; 30.03 54.09];

Ageb50Apr21     = [16.88 24.20; 33.39 25.53];

FemaleApr21     = [21.89 24.85; 31.57 21.70];

%--------------------------------------------------------------------------
%                        May, 2022
%--------------------------------------------------------------------------

NotEVOwnerMay22 = [29.37 26.33; 26.97 17.33];  
EVOwnerMay22    = [5.59 13.13; 27.18 54.10];

Ageb50May22     = [18.76 22.26; 32.15 26.83];

FemaleMay22     = [26.45 24.38; 28.23 20.95];
%--------------------------------------------------------------------------
%                       May-June, 2023
%--------------------------------------------------------------------------

EVInfra1MJ23  = [37.00 26.51; 23.34 13.15];
EVInfra2MJ23  = [4.43 12.83; 33.97 48.77];

NotEVOwnerMJ23 = [34.07 25.43; 25.22 15.28];
EVOwnerMJ23    = [9.36 13.67; 25.12 51.85];

Ageb50MJ23     = [23.54 22.34; 30.35 23.77];

FemaleMJ23     = [32.16 23.15; 25.11 19.58];


%--------------------------------------------------------------------------
x = [1 2];

%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% EVInfo1 (Little or nothing at all). April 2021.

subplot(6,3,1); p1=bar(EVInfo1Apr21,'stacked','FaceColor','flat');
xlabel({'EV Info (Little or Nothing at all)';'April 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p1(1).FaceColor = [0.4 0.4 0.4] ;
p1(2).FaceColor = [0.85 0.85 0.85];

% P = findobj(gca,'type','patch');
% C = [0.85 0.85 0.85; 0.4 0.4 0.4];     % make a colors list 
% for i=1:length(P) 
% set(P(i),'FaceColor',C(i,:));
% end

for i=1:length(x)
  TH1(i) = text(x(i),EVInfo1Apr21(i),num2str(EVInfo1Apr21(i))) ;
  TH2(i) = text(x(i),sum(EVInfo1Apr21(i,:)),num2str(sum(EVInfo1Apr21(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


subplot(6,3,2); p2=bar(EVInfo2Apr21,'stacked','FaceColor','flat');
xlabel({'EV Info (Read or heard a lot)';'April 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p2(1).FaceColor = [0.4 0.4 0.4] ;
p2(2).FaceColor = [0.85 0.85 0.85];

% P = findobj(gca,'type','patch');
% C = [0.85 0.85 0.85; 0.4 0.4 0.4];     % make a colors list 
% for i=1:length(P) 
% set(P(i),'FaceColor',C(i,:));
% end

for i=1:length(x)
  TH1(i) = text(x(i),EVInfo2Apr21(i),num2str(EVInfo2Apr21(i))) ;
  TH2(i) = text(x(i),sum(EVInfo2Apr21(i,:)),num2str(sum(EVInfo2Apr21(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% Env Impact. April 2021

subplot(6,3,3); p3=bar(Env1Apr21,'stacked','FaceColor','flat');
xlabel({'Env Impact (About the same or worse)'; 'April 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p3(1).FaceColor = [0.4 0.4 0.4] ;
p3(2).FaceColor = [0.85 0.85 0.85];


%for i=1:length(x)
  TH1(1) = text(x(1),Env1Apr21(1),num2str(Env1Apr21(1))) ;
  TH2(1) = text(x(1),sum(Env1Apr21(1,:)),num2str(sum(Env1Apr21(1,:))));

  TH1(2) = text(x(2),Env1Apr21(2)+1,num2str(Env1Apr21(2))) ;
  TH2(2) = text(x(2),sum(Env1Apr21(2,:))+10,num2str(sum(Env1Apr21(2,:))));
%end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;



subplot(6,3,4); p4=bar(Env2Apr21,'stacked','FaceColor','flat');
xlabel({'Env Impact (Better)';'Arpil 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p4(1).FaceColor = [0.4 0.4 0.4] ;
p4(2).FaceColor = [0.85 0.85 0.85];

for i=1:length(x)
  TH1(i) = text(x(i),Env2Apr21(i),num2str(Env2Apr21(i))) ;
  TH2(i) = text(x(i),sum(Env2Apr21(i,:)),num2str(sum(Env2Apr21(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% EV Infra. May-June 2023.

subplot(6,3,5); p5=bar(EVInfra1MJ23,'stacked','FaceColor','flat');
xlabel({'EV Infra (Somewhat, not too, and'; 'not at all confident). May-June 2023'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p5(1).FaceColor = [0.4 0.4 0.4] ;
p5(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),EVInfra1MJ23(i),num2str(EVInfra1MJ23(i))) ;
  TH2(i) = text(x(i),sum(EVInfra1MJ23(i,:)),num2str(sum(EVInfra1MJ23(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


subplot(6,3,6); p6=bar(EVInfra2MJ23,'stacked','FaceColor','flat');
xlabel({'EV Infra (Extremely and very';'confident). May-June 2023'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p6(1).FaceColor = [0.4 0.4 0.4] ;
p6(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),EVInfra2MJ23(i),num2str(EVInfra2MJ23(i))) ;
  TH2(i) = text(x(i),sum(EVInfra2MJ23(i,:)),num2str(sum(EVInfra2MJ23(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% EV Owner. April 2021.

subplot(6,3,7); p7=bar(NotEVOwnerApr21,'stacked','FaceColor','flat');
xlabel({'Not a EV Owner';'April 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p7(1).FaceColor = [0.4 0.4 0.4] ;
p7(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),NotEVOwnerApr21(i),num2str(NotEVOwnerApr21(i))) ;
  TH2(i) = text(x(i),sum(NotEVOwnerApr21(i,:)),num2str(sum(NotEVOwnerApr21(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


subplot(6,3,8); p8=bar(EVOwnerApr21,'stacked','FaceColor','flat');
xlabel({'EV Owner';'April 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p8(1).FaceColor = [0.4 0.4 0.4] ;
p8(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),EVOwnerApr21(i),num2str(EVOwnerApr21(i))) ;
  TH2(i) = text(x(i),sum(EVOwnerApr21(i,:)),num2str(sum(EVOwnerApr21(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;

%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% EV Owner. May 2022.

subplot(6,3,9); p9=bar(NotEVOwnerMay22,'stacked','FaceColor','flat');
xlabel({'Not a EV Owner';'May 2022'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p9(1).FaceColor = [0.4 0.4 0.4] ;
p9(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),NotEVOwnerMay22(i),num2str(NotEVOwnerMay22(i))) ;
  TH2(i) = text(x(i),sum(NotEVOwnerMay22(i,:)),num2str(sum(NotEVOwnerMay22(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


subplot(6,3,10); p10=bar(EVOwnerMay22,'stacked','FaceColor','flat');
xlabel({'EV Owner';'May 2022'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p10(1).FaceColor = [0.4 0.4 0.4] ;
p10(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),EVOwnerMay22(i),num2str(EVOwnerMay22(i))) ;
  TH2(i) = text(x(i),sum(EVOwnerMay22(i,:)),num2str(sum(EVOwnerMay22(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;

%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% EV Owner. May-June 2023.

subplot(6,3,11); p11=bar(NotEVOwnerMJ23,'stacked','FaceColor','flat');
xlabel({'Not a EV Owner';'May-June 2023'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p11(1).FaceColor = [0.4 0.4 0.4] ;
p11(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),NotEVOwnerMJ23(i),num2str(NotEVOwnerMJ23(i))) ;
  TH2(i) = text(x(i),sum(NotEVOwnerMJ23(i,:)),num2str(sum(NotEVOwnerMJ23(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


subplot(6,3,12); p12=bar(EVOwnerMJ23,'stacked','FaceColor','flat');
xlabel({'EV Owner';'May-June 2023'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p12(1).FaceColor = [0.4 0.4 0.4] ;
p12(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),EVOwnerMJ23(i),num2str(EVOwnerMJ23(i))) ;
  TH2(i) = text(x(i),sum(EVOwnerMJ23(i,:)),num2str(sum(EVOwnerMJ23(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% Age below 50. April 2021.

subplot(6,3,13); p13=bar(Ageb50Apr21,'stacked','FaceColor','flat');
xlabel({'Age < 50';'April 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p13(1).FaceColor = [0.4 0.4 0.4] ;
p13(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),Ageb50Apr21(i),num2str(Ageb50Apr21(i))) ;
  TH2(i) = text(x(i),sum(Ageb50Apr21(i,:)),num2str(sum(Ageb50Apr21(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% Age below 50. May 2022.

subplot(6,3,14); p14=bar(Ageb50May22,'stacked','FaceColor','flat');
xlabel({'Age < 50';'May 2022'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p14(1).FaceColor = [0.4 0.4 0.4] ;
p14(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),Ageb50May22(i),num2str(Ageb50May22(i))) ;
  TH2(i) = text(x(i),sum(Ageb50May22(i,:)),num2str(sum(Ageb50May22(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;


%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% Age below 50. May-June 2023.

subplot(6,3,15); p15=bar(Ageb50MJ23,'stacked','FaceColor','flat');
xlabel({'Age < 50';'May-June 2023'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p15(1).FaceColor = [0.4 0.4 0.4] ;
p15(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),Ageb50MJ23(i),num2str(Ageb50MJ23(i))) ;
  TH2(i) = text(x(i),sum(Ageb50MJ23(i,:)),num2str(sum(Ageb50MJ23(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;





%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% Female. April 2021.

subplot(6,3,16); p16=bar(FemaleApr21,'stacked','FaceColor','flat');
xlabel({'Female';'April 2021'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p16(1).FaceColor = [0.4 0.4 0.4] ;
p16(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),FemaleApr21(i),num2str(FemaleApr21(i))) ;
  TH2(i) = text(x(i),sum(FemaleApr21(i,:)),num2str(sum(FemaleApr21(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;

%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% Female. May 2022

subplot(6,3,17); p17=bar(FemaleMay22,'stacked','FaceColor','flat');
xlabel({'Female';'May 2022'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p17(1).FaceColor = [0.4 0.4 0.4] ;
p17(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),FemaleMay22(i),num2str(FemaleMay22(i))) ;
  TH2(i) = text(x(i),sum(FemaleMay22(i,:)),num2str(sum(FemaleMay22(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;

%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
% Female. May-June 2023

subplot(6,3,18); p18=bar(FemaleMJ23,'stacked','FaceColor','flat');
xlabel({'Female';'May-June 2023'},'FontSize',8)
ylim([0 100])
xlim([0 3])
set(gca, 'XTick', [])
set(gca,'FontSize',8)

p18(1).FaceColor = [0.4 0.4 0.4] ;
p18(2).FaceColor = [0.85 0.85 0.85];


for i=1:length(x)
  TH1(i) = text(x(i),FemaleMJ23(i),num2str(FemaleMJ23(i))) ;
  TH2(i) = text(x(i),sum(FemaleMJ23(i,:)),num2str(sum(FemaleMJ23(i,:))));
end
% Use the handles TH to modify some properties
set(TH1,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
set(TH2,'Horizontalalignment','center',...
'verticalalignment','bottom','FontSize',8) ;
