How to plot categorical line over bar plot?

5 次查看(过去 30 天)
I want to plot a line over each grouped bar plot, like on the figure below. In the code below it is RSMEref of the same size as the RSME bar plot. I have been trying for the while but nothing works. How can I do that?
RSME = [0.0191 0.0291 0.0362 0.0648 0.0884;
0.0176 0.0552 0.0802 0.0961 0.0810;
0.0139 0.1130 0.1737 0.2191 0.1905;
0.0155 0.1792 0.2656 0.2553 0.3259];
c = categorical({'Apples','Oranges','Bananas','Kiwi'});
bar(c,RSME)
RSMEref = [0.0191 0.0383 0.0765 0.1148 0.1530;
0.0176 0.0352 0.0705 0.1057 0.1410;
0.0139 0.0279 0.0558 0.0837 0.1116;
0.0155 0.0311 0.0622 0.0933 0.1244];

回答(1 个)

Amy
Amy 2017-12-12
Hi Aureja,
The x-axis in your figure is on a categorical scale, so you can't plot the numerical data for your lines on the same axis. What you can do is create a second axis overlaying the first in the same figure window. See this documentation page for a few examples of how to do this.
Using this method, you will probably want to set certain axes properties for your second axis by hand in order for it to appear the way you want it to. You can refer to the documentation for axes properties for more information. Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by