-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plot correct percentages when using plot_counts #17
Conversation
Hi! Thank you for identifying this issue and submitting a PR for it. I appreciate your taking the time to improve this library!
I think the reason this behavior exists is because plot_counts is honestly mostly an internal method, and the preferred/main method to use for plotting is plot_likert, which already does the exact conversion you're suggesting: plot-likert/plot_likert/plot_likert.py Lines 222 to 223 in b83b70d
That said, since I'll try out your patch when I have a bit more time, but thanks again for submitting it! I'll try to get around to it soon. |
@@ -52,6 +52,10 @@ def plot_counts( | |||
# Pad each row/question from the left, so that they're centered around the middle (Neutral) response | |||
scale_middle = len(scale) // 2 | |||
|
|||
# scales labels to correct percentages | |||
if plot_percentage: | |||
counts = likert_percentages(counts, scale, from_count=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I wanted to flag really quickly is that there seems to be some mismatch between the named argument here (from_count
) and the one you introduced below (counted
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I wanted to flag really quickly is that there seems to be some mismatch between the named argument here (from_count) and the one you introduced below (counted).
Yes sorry about that, I changed the name from from_count
to counted
at the last minute because I thought it sounded a bit cleaner.
I think the reason this behavior exists is because plot_counts is honestly mostly an internal method, and the preferred/main method to use for plotting is plot_likert, which already does the exact conversion you're suggesting
I agree that plot_counts
does seem to act as mostly an internal method however, it is a very useful tool to have as an external method and it is mentioned in the documentation as an option (it saved me a lot of time !). Maybe it would make more sense to incorporate plot_counts
into plot_likert
as an option to be enabled ? Or maybe to encapsulate the behaivour of plot_counts
in another function that is exposed ?
Anyway thanks for taking the time to review the pull request - this library is really great !
As pointed out in #17, its behavior is somewhat confusing: > plot_percentages seemed to only just add a percentage sign on to the end of the number of respondents rather than convert the number of responses to percentages As a first step towards fixing that problem, this commit gives the argument a (hopefully) more descriptive name.
In this second part of the fix for #17, a new more intuitive behavior is introduced: given a set of pre-computed counts, setting the `compute_percentages` option will re-calculate the counts as percentages, and display the plot accordingly.
I finally got around to fixing this issue in #24 . Thanks again for raising this and proposing a fix! |
Issue
When using plot_count to plot a graph, plot_percentages seemed to only just add a percentage sign on to the end of the number of respondents rather than convert the number of responses to percentages.
Soloution
Modified the likert_percentage function to be able to accept dataframes which are already counted and then added a conditional in plot_count to modify the dataframe accordingly if plot_percentages=True.