I need to make something along the lines of a pyramid plot but not using demographic information.
Essentially, I have several lists of percentages, and I want to plot the average (median) for each list (which I can pre-compute) in a pyramid plot like scheme. My issue is that the pyramid plot appears to take a the feature (eg age) and the frequency associated with that and then finds the percentage from these frequencies and then plots this. So what I am asking is, can I force it to plot the frequency directly rather than letting it working out the percentage itself to plot. Ideally I want to give it tables like this:
Group1:
group median_percentage
1 30
2 15
3 10
4 9
Group2:
group median_percentage
1 12
2 18
3 17
4 27
And then I want to have a pyramid-like plot that will have these numbers along the X-axis.
Any help would be appreciated and help doing this in either R or matplotlib would be great.
This is the sort of figure I would like to recreate Image of pyramid plot
Yes, this is fantastic! Thank you! This is exactly what I was after. One additional question now I have a graph like this working is, can I add a smoothed version of this. So either adding or replacing the bars with a smooth trance so a line is going from the top of one bar to the top of the next for each set? I have tried to do this with geo_smooth but that has not worked so far.
Happy to help :) I think this is what you are looking for:
I also reduced the opacity and the width of the bars, you can go back to the old version if you delete alpha = 0.5 and width = 0.3 from the geom_bar() call. Note: this code will actually give you some warnings because there are too few data to approximate the smooth line, I would go for geom_line() instead of geom_smooth() to be more scientifically precise. Let me know if you need other help :)
Thank you so much. That is exactly the improvement I was looking for. When i tried to modify the code for the exact dataset I am using, I cam across a couple of issues. The major on is the adding of grey bars around the smooth lines and the smooth lines not hitting the tops of the bars as in yours. I also do not get the errors that I get when I run your code on my machine that you told me to expect.
http://postimg.org/image/83hvu2jm9/
Edit - I fixed this and the above and below problem. Thank you again for all your help!
PS when I change it to line, I think that works well but I realized what I really wanted was to change the names of the Group to strings and not numbers and then the line stops working with this error message
The example dataframe is
Any help getting line to work when I change the group labels to a string?
I am glad :D you are welcome!