Asked by Raffael
on 16 Jan 2013

Hi I have the common problem. I have to plot a bar chart with sorted medians for enzymes and the enzymes shall be colored in blue or red depending on their reversibility.

Here is the data:

data = [.142 31 1;.156 7 1;.191 2 0;.251 6 0] %First column is the sorted value %Second column is the index for the YTickLabel %Third column is the reaction direction % Data(1,3) = 1 -> bar in red % Data(1,3) = 0 -> bar in blue uniNames = {'eno','pck','zwf','...'};

%This was the original script....

h = hist(data(1:end,1)) xlabetxt = uniNames(data(:,2)); ylim([0 .5]) text(1:length(xlabetxt),repmat(-max(ylim)/50,length(xlabetxt),1),xlabetxt','horizontalalignment','right','Rotation',90,'FontSize',15) text text(.55,77.5,'A','FontSize',15) ylabel('median log2 fold change','FontSize',15)

*No products are associated with this question.*

Answer by Thorsten
on 16 Jan 2013

Accepted answer

data = [.142 3 1;.156 5 1;.191 2 0;.251 4 0]; %First column is the sorted value %Second column is the index for the YTickLabel %Third column is the reaction direction % Data(1,3) = 1 -> bar in red % Data(1,3) = 0 -> bar in blue uniNames = {'eno','pck','zwf','foo' 'bar'}; %This was the original script....

H = data(:, 1); N = numel(H); for i=1:N h = bar(i, H(i)); if i == 1, hold on, end if data(i, 3) == 1 col = 'r'; else col = 'b'; end set(h, 'FaceColor', col) end set(gca, 'XTickLabel', '')

xlabetxt = uniNames(data(:,2)); ylim([0 .5]); ypos = -max(ylim)/50; text(1:N,repmat(ypos,N,1), ... xlabetxt','horizontalalignment','right','Rotation',90,'FontSize',15)

text(.55,77.5,'A','FontSize',15) ylabel('median log2 fold change','FontSize',15)

Answer by Hello kity
on 18 Jan 2013

Edited by Hello kity
on 18 Jan 2013

you can also manually select bar and color:

bar(1, Data, 'colorcode') hold on bar(2, Data, 'colorcode') , bar (3, Data, 'colorcode')

that is what Thorsten does here:

h = bar(i, H(i));

Iyk
on 17 Apr 2013

AWESOME!!!!!!!!1

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments