
y1_r = [0.0386111111111111						0.0366666666666667						0.0369907407407407						0.306759259259259	];				
y2_r = [0.284398148148148						0.267083333333333						0.282407407407407						0.33162037037037];					
y3_r = [0.288472222222222						0.266851851851852						0.22087962962963						0.256203703703704];					
y4_r = [NaN						NaN						NaN						NaN	];				
y5_r = [NaN						NaN						NaN						NaN	];				
y6_r = [NaN						NaN						NaN						NaN	];				
y7_r = [NaN						NaN						NaN						NaN	];				
y8_r = [0.106944444444444						0						0						0];					
y9_r = [NaN						NaN						NaN						NaN		];			
y10_r = [NaN						NaN						NaN						NaN	];				
y11_r = [NaN						NaN						NaN						NaN	];				
y12_r = [NaN						NaN						NaN						0.137222222222222];					
y13_r = [0.212685185185185						0.173564814814815						0.211712962962963						0.200787037037037];					
y14_r = [0.243148148148148						0.199537037037037						0.22462962962963						0.241111111111111];					
y15_r = [NaN						NaN						NaN						NaN];					
y16_r = [NaN						NaN						0.153111111111111						0.187444444444444];					
y17_r = [0.239166666666667						0.269027777777778						0.22625						NaN	];				
y18_r = [NaN						NaN						NaN						NaN	];				
y19_r = [0.149583333333333						0.109						0.161111111111111						0.220611111111111];					
y20_r = [0.22037037037037						0.183518518518519						0.204166666666667						0.196064814814815];					
y21_r = [0.209861111111111						0.0816666666666667						NaN						NaN	];				
y22_r = [NaN						NaN						NaN						NaN];					
y23_r = [0.234351851851852						0.221342592592593						0.213657407407407						0.19375	];				
y24_r = [0.263935185185185						0.192569444444444						0.0566203703703704						0.0511574074074074];					
y25_r = [0.047037037037037						0.047962962962963						0.0412037037037037						0.0397685185185185	];				
y26_r = [0.0448148148148148						0.039212962962963						0.0368518518518519						0.02625	];				
y27_r = [0.0325925925925926						0.020787037037037						0.0243055555555556						0.0256018518518519];					
y28_r = [0.0371111111111111						0.0662962962962963						0.0661111111111111						0.0380092592592593];					
y29_r = [0.0451851851851852						0.0366203703703704						0.0275462962962963						0.02	];				
y30_r = [0.0281944444444444						0.0312962962962963						0.0249537037037037						0.0226851851851852	];				
y31_r = [0.02875						0.0273148148148148						0.0199537037037037						0.0119907407407407	];				
y32_r = [0.023287037037037						0.0216203703703704						0.0199537037037037						0.0107407407407407];					
y33_r = [0.0143055555555556						0.0139814814814815						0.0129166666666667						0.01125];					
y34_r = [0.0115740740740741						0.0118981481481481						0.00893518518518518						0.0104166666666667];					

y_values = [
    y1_r; y2_r; y3_r; y4_r; y5_r; y6_r; y7_r; y8_r; y9_r;...
    y10_r; y11_r; y12_r; y13_r; y14_r; y15_r; y16_r; y17_r; y18_r; y19_r;...
    y20_r; y21_r; y22_r; y23_r; y24_r; y25_r; y26_r; y27_r; y28_r; y29_r;...
    y30_r; y31_r; y32_r; y33_r; y34_r];


figure(1);
% SEIZURES GRAPH----------------------------------------------

group_names = {
    'DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection',...
    'No Drug Administration',...
    'Saline Injection','Saline Injection','Saline Injection','Saline Injection','Saline Injection','Saline Injection',...
    'No Drug Administration',...
    'DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection'...
    'No Drug Administration',...
    'Saline Injection','Saline Injection','Saline Injection','Saline Injection','Saline Injection','Saline Injection',...
    'No Drug Administration',...
    'DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection','DCZ Injection'};

[N,M] = size(y_values);

% No Drug Administration -> "#33FFD1"
% DCZ Pump -> "#4DBEEE"
% Saline Pump -> "#D95319"
% DCZ Injection -> "#D133FF"
% Saline Injection -> "#EDB120"

colors = {
    "#D133FF","#D133FF","#D133FF","#D133FF","#D133FF","#D133FF",...
    "#33FFD1",...
    "#EDB120","#EDB120","#EDB120","#EDB120","#EDB120","#EDB120",...
    "#33FFD1",...
    "#D133FF","#D133FF","#D133FF","#D133FF","#D133FF","#D133FF",...
    "#33FFD1",...
    "#EDB120","#EDB120","#EDB120","#EDB120","#EDB120","#EDB120",...
    "#33FFD1",...
    "#D133FF","#D133FF","#D133FF","#D133FF","#D133FF","#D133FF"};

subplot(2,1,1);

seizures = [1		0		0		0		0		0		0		0		0		0		0		0		0		0		1		4		1		5		1		0		3		3		0		0		1		1		19		6		0		0		3		0		1		2	];

hold on;

for i = 1:length(seizures)-1
    plot([i i+1], [seizures(i) seizures(i+1)], 'Color', colors{i}, 'LineWidth', 1.1);
    rgb_color = sscanf(colors{i},'#%2x%2x%2x',[1 3])/255; % Convert hexadecimal color to RGB
    scatter(i, seizures(i), 100, rgb_color, 'filled');
end

rgb_color = sscanf(colors{end},'#%2x%2x%2x',[1 3])/255; % Convert hexadecimal color to RGB
scatter(length(seizures), seizures(end), 100, rgb_color, 'filled');

windowSize = 5; 
b = (1/windowSize)*ones(1,windowSize);
a = 1;
moving_avg = filter(b, a, seizures);

plot(1:length(seizures), moving_avg, 'k', 'LineWidth', 2);

x_indices = 1:N;
xticks(x_indices(3:3:end));
xticklabels({'2.11.', '5.11.', '8.11.','11.11.','14.11.',...
    '17.11.','20.11.','23.11.','26.11.','29.11.','2.12.',...
    'Moving Average'});
ax = gca;
ax.FontSize = 13;

h = zeros(length(group_names)+1, 1); 

for i = 1:length(group_names)
    h(i) = scatter(NaN,NaN, 'filled', 'MarkerFaceColor', colors{i}, 'SizeData', 100);
end

h(end) = plot(NaN,NaN, 'k', 'LineWidth', 2);

group_names{end+1} = 'Moving Average';

[unique_group_names, idx] = unique(group_names, 'stable');

legend(h(idx), unique_group_names, 'Location', 'northwest', 'FontSize', 8);

title('Daily Seizure Frequency (FCD025)', 'FontSize', 18);
xlabel('Date', 'FontSize', 13);
ylabel('Seizure Frequency (n/days)', 'FontSize', 13);

xlim([0.5, length(seizures)+0.5]); 

hold off;


% IED GRAPH-----------------------------------------------------

y1_r = [0.0386111111111111						0.0366666666666667						0.0369907407407407						0.306759259259259	];				
y2_r = [0.284398148148148						0.267083333333333						0.282407407407407						0.33162037037037];					
y3_r = [0.288472222222222						0.266851851851852						0.22087962962963						0.256203703703704];					
y4_r = [NaN						NaN						NaN						NaN	];				
y5_r = [NaN						NaN						NaN						NaN	];				
y6_r = [NaN						NaN						NaN						NaN	];				
y7_r = [NaN						NaN						NaN						NaN	];				
y8_r = [0.106944444444444						0						0						0];					
y9_r = [NaN						NaN						NaN						NaN		];			
y10_r = [NaN						NaN						NaN						NaN	];				
y11_r = [NaN						NaN						NaN						NaN	];				
y12_r = [NaN						NaN						NaN						0.137222222222222];					
y13_r = [0.212685185185185						0.173564814814815						0.211712962962963						0.200787037037037];					
y14_r = [0.243148148148148						0.199537037037037						0.22462962962963						0.241111111111111];					
y15_r = [NaN						NaN						NaN						NaN];					
y16_r = [NaN						NaN						0.153111111111111						0.187444444444444];					
y17_r = [0.239166666666667						0.269027777777778						0.22625						NaN	];				
y18_r = [NaN						NaN						NaN						NaN	];				
y19_r = [0.149583333333333						0.109						0.161111111111111						0.220611111111111];					
y20_r = [0.22037037037037						0.183518518518519						0.204166666666667						0.196064814814815];					
y21_r = [0.209861111111111						0.0816666666666667						NaN						NaN	];				
y22_r = [NaN						NaN						NaN						NaN];					
y23_r = [0.234351851851852						0.221342592592593						0.213657407407407						0.19375	];				
y24_r = [0.263935185185185						0.192569444444444						0.0566203703703704						0.0511574074074074];					
y25_r = [0.047037037037037						0.047962962962963						0.0412037037037037						0.0397685185185185	];				
y26_r = [0.0448148148148148						0.039212962962963						0.0368518518518519						0.02625	];				
y27_r = [0.0325925925925926						0.020787037037037						0.0243055555555556						0.0256018518518519];					
y28_r = [0.0371111111111111						0.0662962962962963						0.0661111111111111						0.0380092592592593];					
y29_r = [0.0451851851851852						0.0366203703703704						0.0275462962962963						0.02	];				
y30_r = [0.0281944444444444						0.0312962962962963						0.0249537037037037						0.0226851851851852	];				
y31_r = [0.02875						0.0273148148148148						0.0199537037037037						0.0119907407407407	];				
y32_r = [0.023287037037037						0.0216203703703704						0.0199537037037037						0.0107407407407407];					
y33_r = [0.0143055555555556						0.0139814814814815						0.0129166666666667						0.01125];					
y34_r = [0.0115740740740741						0.0118981481481481						0.00893518518518518						0.0104166666666667];					

y_values = [
    y1_r; y2_r; y3_r; y4_r; y5_r; y6_r; y7_r; y8_r; y9_r;...
    y10_r; y11_r; y12_r; y13_r; y14_r; y15_r; y16_r; y17_r; y18_r; y19_r;...
    y20_r; y21_r; y22_r; y23_r; y24_r; y25_r; y26_r; y27_r; y28_r; y29_r;...
    y30_r; y31_r; y32_r; y33_r; y34_r];

subplot(2,1,2);

baseline_L = 0.144;

hold on;

h(1) = plot([0.5, N+0.5], [baseline_L, baseline_L], 'Color', [178, 189, 216]/255, 'LineWidth', 2); 

mean_values = nanmean(y_values, 2); 

smooth_mean_values = movmean(mean_values, 1, 'Endpoints', 'shrink');

h(2) = plot(1:N, smooth_mean_values, 'LineWidth', 2, 'Color', 'k');

x_new=linspace(0.75,N+0.5,N*M);
x_new=reshape(x_new,M,[])';

for i=1:size(y_values,1)
    h(i+2) = plot(x_new(i,:),y_values(i,:),'Color',colors{i},'Marker','o','LineStyle','-','MarkerFaceColor',colors{i});
end

x_indices = 1:N;
xticks(x_indices(3:3:end));
xticklabels({'2.11.', '5.11.', '8.11.','11.11.','14.11.',...
    '17.11.','20.11.','23.11.','26.11.','29.11.','2.12.',...
    'Baseline', 'Moving Average'});
ax = gca;
ax.FontSize = 13;

group_names{end+1} = 'Baseline'; 
group_names{end+1} = 'Moving Average'; 
[ugn,idx] = unique(group_names([end-1:end 1:end-2]),'stable');
legend(h(idx),ugn,'Location', 'best', 'FontSize', 8);

title({'IED Frequency during Injection Drug Administration (FCD025)'}, 'FontSize', 18);
xlabel('Date', 'FontSize', 13);
ylabel('IED Frequency (n/s)', 'FontSize', 13);

xlim([0.5, N+0.5]); 

hold off;
		
drawnow;
pause(10); 

fig = gcf;
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 10 8];
fig.PaperSize = [10 8]; 

print('frequency_FCD025.png', '-dpng', '-r600');

		