anhoej / qicharts2

R package: Quality improvement charts
38 stars 12 forks source link

Altering x or y axis through ggplot2 replaces existing scale #15

Closed lenakba closed 5 years ago

lenakba commented 5 years ago

When creating a qic-chart, if you want to make changes to the x or y axes with ggplot2-commands outside of the qic-command, without having specified how the x y axis should be inside the qic-command, you replace a previously defined axis and receive a message.

Example:

library(qicharts2)

qic(x = i, y = r, n = n, data = nhs_accidents, chart = "p") +
scale_y_continuous(breaks = c(0.95, 0.96))

Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.

A suggestion for improvement is for the user to not receive the message if they have not specified the x or y axis in the qic-command when they make the axis-specifications with ggplot2.

anhoej commented 5 years ago

Thanks, and hmm ... I'll think about your suggestion. I get your point. But I also find the ggplot message useful.

Try: qic(x = i, y = r, n = n, data = nhs_accidents, chart = "p", y.percent = F)

The real problem, as I see it, is that ggplot2 (or scales) add too many decimals to percent formatted y axes.

lenakba commented 5 years ago

I agree, the ggplot message is useful.

How about an argument called something like "add_axes", when TRUE, adds the axes defined by qic (default), when FALSE, the qic-command won't change the axes, and you're free to alter them without the message. Or a separate argument for the X axis and one for Y...not sure what would be the best solution.

Your suggested code works, but it doesn't solve our particular problem. We want to add percentages to the scale that are correct according to Norwegian grammar. Thus, we have to add these labels in scale_y_continuous either way.