I have been fiddling with a stacked bar chart, which I cannot get to sort from tallest to shortest. Here is the chart I have currently.
The code I am using is below:
ggplot(df7, aes(
x = reorder(cause, failures) ,
y = failures,
fill = factor(
part_number,
levels = c(
"UNKNOWN",
"3766453",
"20R7920",
"3966006",
"3976397",
"20R7916",
"20R7915"
)
)
)) +
geom_bar(
position = "stack",
stat = "identity",
width = 0.7,
alpha = 0.75,
color = 'black'
) +
theme_minimal() +
xlab('') +
ylab('Failures') +
labs(fill = "Part Number") +
scale_fill_brewer(palette = "Dark2") +
coord_flip()
Does anyone see why the chart is not sorting correctly? Thank you, and cheers!