Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Plot correct percentages when using plot_counts #17

wants to merge 1 commit into from

Conversation

charliertm
Copy link

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.

@nmalkin
Copy link
Owner

nmalkin commented Mar 13, 2021

Hi! Thank you for identifying this issue and submitting a PR for it. I appreciate your taking the time to improve this library!

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.

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:

if plot_percentage:
counts = likert_percentages(df_fixed, format_scale, label_max_width, drop_zeros)

That said, since plot_counts is being exposed, I agree that its behavior is confusing and unexpected, so I think the change you're proposing makes sense.

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)
Copy link
Owner

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).

Copy link
Author

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 !

nmalkin added a commit that referenced this pull request Dec 28, 2021
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.
nmalkin added a commit that referenced this pull request Dec 28, 2021
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.
@nmalkin
Copy link
Owner

nmalkin commented Dec 28, 2021

I finally got around to fixing this issue in #24 . Thanks again for raising this and proposing a fix!

@nmalkin nmalkin closed this Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants