Thank you for posting! Here is an outline of an effective post:
Got another challenge while trying to plot multiple bar charts with percentages on the y-axis. When I ran this code with numbers everything worked fine.
ggplot(
data = regions,
mapping = aes(
x = species,
fill = Phenotype)) + scale_fill_manual(values = phenotype_colors) +
geom_bar() +
scale_y_continuous(breaks = seq(from = 0,
to = 10000,
by = 1000),
expand = c(0,0)) +
scale_x_discrete(expand = c(0,0))+
coord_flip()+
theme_classic()+
facet_wrap(~ Regions)+
labs(title = ) +
xlab(“WHO priority pathogens”) + ylab(“Number of isolates”)
But with this code some rows are deleted even though there are no missing data
ggplot(
data = regions2,
mapping = aes(
x = species, y = percentages,
fill = Phenotype)) +
geom_bar(stat=“identity”) +
scale_fill_manual(values = phenotype_colors) +
scale_y_continuous(labels = scales::percent, limits = c(0, 1)) +
scale_x_discrete(expand = c(0, 0)) +
coord_flip() +
facet_wrap(~ Regions) +
labs(
title = ,
x = “Species”,
y = “Percentage”)
If you remove the line where it says coord_flip() + from your code that will result in the y-axis showing percentages. However, I don’t think any data is missing in your facets, they all share the same x-axis scale (which appears as the y-axis in your plot due to the coordinate flip mentioned above).
The problem is not solved. Please see below the chart when I used “number of isolates” as opposed to “percentages”. You will observe that some bars are missing in the chart with percentages.
It looks to me that your percentages are calculated incorrectly but it’s hard to be sure without having access to a reproducible example.
My recommendation would be to review your percentages to make sure that they are valid and to create a reproducible example so that I and others can properly assess the situation.