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

stat_pareto mislabels the x axis unless x data are alphabetized #41

Open
rlittle08 opened this issue May 14, 2019 · 2 comments
Open

stat_pareto mislabels the x axis unless x data are alphabetized #41

rlittle08 opened this issue May 14, 2019 · 2 comments

Comments

@rlittle08
Copy link

While the bars show up in the correct order (largest to smallest), their labels are incorrect any time x is not in alphabetical order. Could this be fixed?

# first set alphabetized, second not, but with same value order
sorted     <- data.frame(label = c("A",   "B",   "C",     "D"),    value = c(20, 15, 10, 5))    
not_sorted <- data.frame(label = c("One", "Two", "Three", "Four"), value = c(20, 15, 10, 5))    

# this one labels bars correctly
ggplot(sorted, aes(x = label, y = value)) +

    ggQC::stat_pareto(point.color = "red",
                point.size = 2,
                line.color = "black",
                bars.fill = c("coral", "yellow"))
    
# this one does not label bars correctly
ggplot(not_sorted, aes(x = label, y = value)) +

    ggQC::stat_pareto(point.color = "red",
                point.size = 2,
                line.color = "black",
                bars.fill = c("coral", "yellow"))
@krt2023
Copy link

krt2023 commented Apr 6, 2023

The package still has this same issue. Thanks to rlittle08 for pointing it out.

@Wang-Yong2018
Copy link

It can be solved by new_df <- df |> arrange(desc(cost)) |> mutate(x=fct_reorder(x,desc(y)).
I love ggQC package and use it recently. I found the same issue and the most convinent way is just prepare the input data frame by arrange + fct_reorder.

Below is the full cost to demo purpose:

`library(ggQC)
library(ggplot2)
library(forcats)
library(tidyverse)

set.seed(0)
df <- data.frame(
x = c('a', 'd', 'c', 'H1', 'Y1',
'B', 'AAA', 'Xy', '2A', '12'),
y = as.integer(runif(
n = 10, min = 0, max = 100
))
)
print(str(df |> arrange(desc(y))))

when x= Xy',y = 94, which is biggest.
Bug code from the Render Pareto Plot from ggQC onine help -------------
which put H1 in the 1st place incorrectly.
ggplot(df, aes(x = x, y = y)) +
stat_pareto(
point.color = "red",
point.size = 3,
line.color = "black",
#size.line = 1,
bars.fill = c("blue", "orange")
)

Fixed cost from Render Pareto Plot from ggQC onine help ---------------
arrange y value by desc, and mutate the x by fct_recorder
which put Xy in the 1st place incorrectly.
new_df <- df |>
arrange(desc(y)) |>
mutate(x = fct_reorder(x, desc(y)))

ggplot(new_df, aes(x = x, y = y)) +
stat_pareto(
point.color = "red",
point.size = 3,
line.color = "black",
#size.line = 1,
bars.fill = c("blue", "orange")
)
`
if you love the answer, pls vote it. thanks

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

No branches or pull requests

3 participants