Creating sigstar in bar graph
68 views (last 30 days)
Show older comments
Hi everybody,
I'm trying to create a significant star between two bars (the values 0.1423 and 0.3203) in a bar graph like:
y = [0.1423 0.3203; 0.1232 0.1325; 0.1297 0.1302];
bar(y)
Labels = {'first', 'second, 'third'};
set(gca, 'XTick', 1:6, 'XTickLabel', Labels);
colormap(gray)
and then trying to use the function sigstar but it keeps doing it between the first and second row.
Does anyone know how to make a sigstar between the first and second value?
Thanks a lot in advance.
Eric
0 Comments
Accepted Answer
Star Strider
on 5 Feb 2015
This is indirectly the courtesy of Kelly Kearney (in absentia) who figured out how to access the bar centre location data in R2014b HG2 :
y = [0.1423 0.3203; 0.1232 0.1325; 0.1297 0.1302];
hBar = bar(y)
Labels = {'first', 'second', 'third'};
set(gca, 'XTick', 1:6, 'XTickLabel', Labels);
colormap(gray)
ctr2 = bsxfun(@plus, hBar(2).XData, [hBar(2).XOffset]');
hold on
plot(ctr2(1:2), [1 1]*y(1,2)*1.1, '-k', 'LineWidth',2)
plot(mean(ctr2(1:2)), y(1,2)*1.15, '*k')
hold off
produces:
You will likely want to experiment with it to get the appearance you want.
1 Comment
Stephanie Warnken
on 30 Nov 2016
I am attempting to do this however I keep getting the error:
Subscript indices must either be real positive integers or logicals.
Error in NMDbargraphs (line 87)
plot(ctr2(1:2), [1 1]*y(1,2)*1.1, '-k', 'LineWidth',2)
This is my script:
Xlabels = {'PLSCR2','KLRD1','SLC25A41','DKK1','SCNN1B','HERC6','ABCA6','SLC6A14','HERC5','WNT5A','SLC7A11','ADAM32','HLA-DRB5','HLA-DQA1','TXK'};
y = [0 1.24995; 0 0.913261; 0 0.771555; 26.3909 179.674; 15.9778 50.1741; 8.37013 35.9429; 3.18104 17.8539; 1.131156 10.3382; 1.6023 9.71669; 1.53533 7.86248; 1.18668 5.10144; 0.077432 2.72368; 0 1.87032; 0 1.08509; 0 0.79633];
x=1:length(y);
figure
hBar = bar(y);
set(gca,'xticklabel', Xlabels);
set(hBar(1), 'FaceColor','b');
set(hBar(2), 'FaceColor','r');
rotateticklabel(gca, 45, 18);
ylabel('Gene Expression Level','FontSize',18,'FontWeight','bold');
h=legend('NMD','NMD inhibited');
set(h,'location','Northwest', 'Fontsize', 18);
for i = 1:length(y)
NMD(i) = y(i,1);
noNMD(i) = y(i,2);
i = i+1;
end
n=2*length(NMD);
set(gca, 'XTick', 1:n)
ctr2 = bsxfun(@plus, hBar(2).XData, [hBar(2).XOffset]');
hold on
plot(ctr2(1:2), [1 1]*y(1,2)*1.1, '-k', 'LineWidth',2)
plot(mean(ctr2(1:2)), y(1,2)*1.15, '*k')
hold off
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!