I need help on how to generate a reversed stacked bar plot with specific ylim. I have used the code below for this purpose but the plot is generated in reverse order as expected but the ylim option did not work i.e, the y-axis labels were auto generated.
This is the data:
df <- structure(list(z = c("up", "up", "up", "up", "up", "up", "down",
"down", "down", "down", "down", "down"), x = c("C", "C", "G", "G", "H", "H",
"C", "C", "G", "G", "H", "H"), w = c("more", "less", "more", "less", "more",
"less", "more", "less", "more", "less", "more", "less"), y = c(5, 6, 4, 4,
50, 42, 50, 16, 24, 8, 83, 99)), class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -12L)
My code is
ggplot(df, aes(x, y, fill=w))+geom_bar(stat='identity')+ facet_wrap(~z, scales="free_y", ncol = 1) +xlab('a')+ylab('b')+theme(panel.background = element_blank(),axis.text = element_text(size = 8, color = 'black'), text = element_text(size = 8),plot.title = element_text(hjust = 0.5))+ggtitle('T')+ ylim(0,500)+scale_y_continuous(trans="reverse")
However, using the same code without reversing the plot generates a stacked plot in an upright position and with ylim as specified.
ggplot(df, aes(x, y, fill=w))+geom_bar(stat='identity')+ facet_wrap(~z, scales="free_y", ncol = 1) +xlab('a')+ylab('b')+theme(panel.background = element_blank(),axis.text = element_text(size = 8, color = 'black'), text = element_text(size = 8),plot.title = element_text(hjust = 0.5))+ggtitle('T')+ ylim(0,500)
"scale_y_continuous(trans="reverse")",
I need help on how to successfully generate this plot. Thanks
