figS3CD_BarChart.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. %% fig. S3CD - BarChart
  2. clear all
  3. close all
  4. % ==========================================================================
  5. %% Sensory responsive cell barchart
  6. % ==========================================================================
  7. %Prepare variables
  8. load('figS3B_BarChart.mat');
  9. NofMouse = 4;
  10. Aud = 0; %For fig. S3C
  11. Vis = 1; %For fig. S3D
  12. if Aud
  13. MouseID = 1:4;
  14. elseif Vis
  15. MouseID = 5:8;
  16. end
  17. % ============================================================================================
  18. %% Proportion of cells from each mouse for each cluster - Bar chart (mean)+ SEM - For figures
  19. % ============================================================================================
  20. for iLearning = 1:2 %Initial or Reversal
  21. RatioData = [];
  22. Mean4Bar = [];
  23. SEM4Bar = [];
  24. switch iLearning
  25. case 1 %Initial Learning
  26. fig1 = figure('Name', 'InitialLearning-GoNogoCellRatio');
  27. RatioData = CellRatio_Initial;
  28. title('Proportion of cell types - Go - Ini');
  29. hold on;
  30. Mean4Bar = [mean(RatioData{1,iLearning}(MouseID,:),1); mean(RatioData{1,iLearning+1}(MouseID,:),1)];
  31. SEM4Bar = [std(RatioData{1,iLearning}(MouseID,:),0,1)/sqrt(NofMouse); std(RatioData{1,iLearning+1}(MouseID,:),0,1)];
  32. case 2 %Reversal Learning
  33. fig2 = figure('Name', 'ReversalLearning-GoNogoCellRatio');
  34. RatioData = CellRatio_Reversal;
  35. title('Proportion of cell types - Go - Rev');
  36. hold on;
  37. Mean4Bar = [mean(RatioData{1,iLearning-1}(MouseID,:),1); mean(RatioData{1,iLearning}(MouseID,:),1)];
  38. SEM4Bar = [std(RatioData{1,iLearning-1}(MouseID,:),0,1)/sqrt(NofMouse); std(RatioData{1,iLearning}(MouseID,:),0,1)];
  39. end %switch
  40. %Plot bar chart
  41. b = bar(1:size(Mean4Bar,2), Mean4Bar, 'grouped','FaceColor', 'none', 'EdgeColor', 'k');
  42. hold on;
  43. % Calculate the number of groups and number of bars in each group
  44. [nbars,ngroups] = size(Mean4Bar);
  45. % Get the x coordinate of the bars
  46. x = nan(nbars, ngroups);
  47. for i = 1:nbars
  48. x(i,:) = b(i).XEndPoints;
  49. end
  50. %Plot error bar
  51. er = errorbar(x, Mean4Bar, SEM4Bar);
  52. %er is 1x4 struct structure
  53. for e=1:size(Mean4Bar,2)
  54. er(1,e).Color = [0 0 0];
  55. er(1,e).LineStyle = 'none';
  56. er(1,e).MarkerEdgeColor = 'none';
  57. end
  58. xticks([1 2 3 4]);
  59. xticklabels({'Go', 'Nogo', 'Both', 'Non'});
  60. box off
  61. ylim([0 0.8]);
  62. yticks([0 0.2 0.4 0.6 0.8 1.0]);
  63. ylabel('Proportion of cells')
  64. %Dot color
  65. Group1Color = [0.75 0.75 0.75];
  66. for ii = 1:2 %1 = Naive, 2 = Expert
  67. Group1Cluster = [];
  68. Group1Cluster = RatioData{1,ii}(MouseID, :);
  69. sz = 20;
  70. ScatterID = repmat(x(ii,:), size(Group1Cluster,1),1);
  71. scatter(ScatterID(:),Group1Cluster(:), [], Group1Color, 'filled','MarkerFaceAlpha',0.5','jitter','on','jitterAmount',0.075);
  72. end% ii
  73. end %for iLearning