figS3B_BarChart.m 3.8 KB

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