

function dnn_results_plots(dnnType,dnnCorrType,rsa_tag,roi_tag,direction,phase,memtype)

    %set dnnType
    if contains(dnnType,'AlexNet')
        layerNum = 8;
        layerNames = {'conv1','conv2','conv3','conv4','conv5','fc6','fc7','fc8'};
        %cmap = cbrewer('seq','YlGnBu',layerNum); cmap(cmap>1) = 1; cmap(cmap<0) = 0;

        cmap = cbrewer('div','Spectral',layerNum); cmap(cmap>1) = 1; cmap(cmap<0) = 0;
        %cmap = cbrewer('seq','YlGnBu',layerNum); cmap(cmap>1) = 1; cmap(cmap<0) = 0;
        cmap = flipud(cmap);
    elseif contains(dnnType,'Google')
        layerNum = 1;
        layerNames = {'GoogleSemantic'};
        cmap = [0.5 0.5 0.5];
    end

    %%% get times of sig ERS cluster
    dir = ['..\STATS\ItemDNN\' dnnType '_spearman\300width_50step_1500ms\' roi_tag];
    cd(dir);
    %get clustertimes of ERS cluster
    if strcmp(roi_tag,'BA20') || strcmp(roi_tag,'BA17_18_19') || strcmp(roi_tag,'BA17_18') ||strcmp(roi_tag,'BA37') || strcmp(roi_tag,'BA19')
        ERS_direction = 'pos';
    elseif strcmp(roi_tag,'BA40') || strcmp(roi_tag,'BA40_bprow') || strcmp(roi_tag,'BA40_bprows') || strcmp(roi_tag,'BA39_40')
        ERS_direction = 'neg';
    end
    [clusteridx,enctime,rectime]= extract_ersclusteridx_032122('300width_50step_1500ms','item-specific\diff_memcat_row_1000rep','memory',roi_tag,ERS_direction);

    
    figure('renderer','painters','position',[350 450 350 260]);

    %load clusterstats
    load(['clusterstats_' phase '_' memtype '.mat'])

    %%% find all sig layers for this contrast and their respective timepoints
    sig = {}; sig.layer = {}; sig.idx = []; sig.layernum = [];

    if strcmp(direction,'pos')
        for k = 1:layerNum
            if clusterstats.(layerNames{k}).pos.p < 0.05
                sig.layer{end+1} = layerNames{k}; sig.layernum(end+1) = k;
                sig.idx{end+1} = find(clusterstats.(layerNames{k}).pos.map == clusterstats.(layerNames{k}).pos.idx);
            end
        end
    elseif strcmp(direction,'neg')
        for k = 1:layerNum
            if clusterstats.(layerNames{k}).neg.p < 0.05
                sig.layer{end+1} = layerNames{k}; sig.layernum(end+1) = k;
                sig.idx{end+1} = find(clusterstats.(layerNames{k}).neg.map == clusterstats.(layerNames{k}).neg.idx);
            end
        end
    end

    %encoding or recognition
    load(['groupstats_' phase '.mat']);
    gcf;
    for lay = 1:layerNum
        if ~ismember(lay,sig.layernum) %ns layers
            % l =
            % plot(1:25,groupstats.emp.(memtype).t(:,lay)',':','Color',cmap(lay,:),'LineWidth',3);
            % hold on; %previous version with n.s. dotted line
            l = plot(1:25,groupstats.emp.(memtype).t(:,lay)','Color',cmap(lay,:),'LineWidth',5); hold on;

            %l.Color(4) = 0.6;
        else
            plot(1:25,groupstats.emp.(memtype).t(:,lay)','Color',cmap(lay,:),'LineWidth',5); hold on;
        end
    end

    %prep layerNames
    legend(layerNames,'AutoUpdate','off');

    xticks([3:5:25]); 
    set(gca,'XTickLabel',{'250','500','750','1000','1250'},'fontsize',12)

    if strcmp(phase,'enc')
        xlabel('encoding time');
    else
        xlabel('recognition time');
    end
    ylabel('t-value');
    yline(0);
    if strcmp(direction,'pos')
        ylim([-2.5 4]);
    elseif strcmp(direction,'neg')
        ylim([-5 2.5]);
    end
    %yticklabels('FontSize',4)
    
    if strcmp(direction,'pos')
        ys_bar = linspace(-1,-2,layerNum);
    elseif strcmp(direction,'neg')
        ys_bar = linspace(1,2,layerNum);
    end
    
    for li = 1:layerNum
        if clusterstats.(layerNames{li}).(direction).p < 0.05
            xs = find(clusterstats.(layerNames{li}).(direction).map == clusterstats.(layerNames{li}).(direction).idx);
            plot(xs,repelem(ys_bar(li),length(xs)),'LineWidth',2.5,'Color',cmap(li,:))
        end
    end

    %mark sig timepoints with lines for MEMORY plot (Encoding)
%     if strcmp(roi_tag,'BA20') && strcmp(direction,'pos') && strcmp(memtype,'mem') && strcmp(dnnType,'AlexNet_avg')
%         %fc7
%         fc7_idx = find(clusterstats.fc7.pos.map == clusterstats.fc7.pos.idx);
%         plot(fc7_idx,repelem(-0.5,length(fc7_idx)),'LineWidth',2.5,'Color',cmap(7,:)) 
%         %fc8
%         fc8_idx = find(clusterstats.fc8.pos.map == clusterstats.fc8.pos.idx);
%         plot(fc8_idx,repelem(-0.7,length(fc8_idx)),'LineWidth',2.5,'Color',cmap(8,:))
%     elseif strcmp(roi_tag,'BA20') && strcmp(memtype,'forg') %rem ns
%         cos = [1.7:0.15:2.75];
%         for k = 1:length(sig.layer)
%             plot(sig.idx{k},repelem(cos(k),length(sig.idx{k})),'LineWidth',2.5,'Color',cmap(sig.layernum(k),:)) 
%         end
%     elseif strcmp(roi_tag,'BA40') 
%         cos = [1.7:0.15:2.15];
%         for k = 1:length(sig.layer)
%             plot(sig.idx{k},repelem(cos(k),length(sig.idx{k})),'LineWidth',2.5,'Color',cmap(sig.layernum(k),:)) 
%         end
%     elseif strcmp(roi_tag,'BA37') && strcmp(direction,'pos')
%         cos = [-1:(1/8):-2];
%         for k = 1:length(sig.layer)
%             plot(sig.idx{k},repelem(cos(k),length(sig.idx{k})),'LineWidth',2.5,'Color',cmap(sig.layernum(k),:)) 
%         end
%     end

    if strcmp(roi_tag,'BA20') || strcmp(roi_tag,'BA40')
        if strcmp(phase,'enc')
            xline(min(enctime),'--','LineWidth',1.5); xline(max(enctime),'--','LineWidth',1.5);
        else
            xline(min(rectime),'--','LineWidth',1.5); xline(max(rectime),'--','LineWidth',1.5);
        end
    end
    set(gcf,'color','white')
    
    %print clusterstats per layer
    for k = 1:layerNum
        vals = clusterstats.(layerNames{k}).(direction);
        disp([layerNames{k} ' t sum = ' num2str(vals.sum) ' , nbin = ' num2str(length(find(vals.map==vals.idx))) ' , p cluster = ' num2str(vals.p)])
    end
    title(memtype)
    hold on;
    
    %%% if sig ERS, plot post-hoc bar plot for each layer with avg scores
    %%% over timepoints of sig ERS cluster
    if strcmp(roi_tag,'BA20')
        onset = min(enctime); offset = max(enctime);
        %get avg 
        cluster_avg = squeeze(nanmean(groupstats.sub.emp.(memtype).t(:,enctime,:),2)); %nsubs * n layers
        %plot barscatter for each layer in color scheme
        plot_barscatter_dnnlayers(cluster_avg,cmap,layerNum,layerNames)
    end
end
