How to edit histograms?

13 views (last 30 days)
Bora Semiz
Bora Semiz on 15 Jan 2014
Answered: Bora Semiz on 17 Jan 2014
Hello guys! I have Data Mining class and in order to prepare my report I have to know more about histograms.
I have a file, which I attach this thread, showing a log which belongs to a phone company. The last column ("churn") indicates that if the user resigned from the operator or not. My mission is to find interesting relationships showing why user have resigned from the operator. For example, I choose one of the columns (e.g Day Mins) and examine it. If people who has lots of day mins tend to resign, I have to prove this.
I want to plot an histogram for indicating that. I have the information of who has resigned or not as true or false values. So how can I split each bar into two bars. A single bar will contain two bars. One bar at the down is people who have resigned and the other bar at the top will be the people who did not resign. In attachment I also giving you the plot that I made.

Accepted Answer

AJ von Alt
AJ von Alt on 17 Jan 2014
You can plot multiple histograms on a single set of axes using the hold command.
If I understand you correctly you want a histogram that looks like this:
This can be achieved by using hold to overlay the resigned histogram over the total histogram.
To do so plot your first histogram:
bar( centers , n , 'b' )
Turn on hold to prevent overwriting the first histogram:
hold on
Plot your second histogram:
bar( centers , n2 , 'r' )
Finally, turn off hold when your are done:
hold off
The following code gives you an example for two randomly generated data sets dayMinsUnresigned and dayMinsResigned. To use this code with your data you will first have to sort dayMins into the two vectors. Logical indexing would be a good place to get started with that.
dayMinsUnresigned = 10*rand(1 , 100);
dayMinsResigned = 10*rand(1 , 100);
%Histogram for each input using the same centers
[nUnresigned , minuteCenters] = hist( dayMinsUnresigned );
nResigned = hist( dayMinsResigned, minuteCenters );
%Sum the bins so that the second data set appears above the first
nSum = nUnresigned + nResigned;
bar(minuteCenters , nSum , 'b' ) %create the total histogram
% turn on hold so you can add another histogram to the same axis
hold on
bar(minuteCenters , nResigned , 'r' )
% do not forget to turn off hold when you're done!
hold off
legend('Not Resigned' , 'Resigned' )

More Answers (1)

Bora Semiz
Bora Semiz on 17 Jan 2014
I am really appreciated. Thanks :)

Community Treasure Hunt

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

Start Hunting!