I am trying to create a stacked histogram or bar graph with an overlying line graph and am having trouble.
My dataset is patients who have undergone heart transplant using either "expanded" or "not_expanded" donor hearts where the varname is "expanded" with 0= no and 1= yes. I also have the varname "not_expanded" where 0=no and 1=yes, such that "expanded" and "not_expanded" are inversions of each other. The varname "yot" is the year the transplant occurred.
To get a stacked bar graph, I use the following code:
graph bar (sum) expanded not_expanded, over (yot), stack
and it looks great.
To create a histogram of all transplants (not stacking expanded and not_expanded) with a line graph of the median sequence number for that year (varname med_seq), I use the following code:
egen med_seq = median(seq_num), where "seq_num" is the sequence number for each patient
histogram yot, discrete frequency addplot((line med_seq yot, sort))
and it also looks great.
The question is, how do I get the line graph over the stacked bar graph or histogram so I can represent bot the median sequence numbers (as a line) as well as the frequency of both expanded and not expanded transplants?
Thanks!
My dataset is patients who have undergone heart transplant using either "expanded" or "not_expanded" donor hearts where the varname is "expanded" with 0= no and 1= yes. I also have the varname "not_expanded" where 0=no and 1=yes, such that "expanded" and "not_expanded" are inversions of each other. The varname "yot" is the year the transplant occurred.
To get a stacked bar graph, I use the following code:
graph bar (sum) expanded not_expanded, over (yot), stack
and it looks great.
To create a histogram of all transplants (not stacking expanded and not_expanded) with a line graph of the median sequence number for that year (varname med_seq), I use the following code:
egen med_seq = median(seq_num), where "seq_num" is the sequence number for each patient
histogram yot, discrete frequency addplot((line med_seq yot, sort))
and it also looks great.
The question is, how do I get the line graph over the stacked bar graph or histogram so I can represent bot the median sequence numbers (as a line) as well as the frequency of both expanded and not expanded transplants?
Thanks!
Comment