I want to make the bar heights of a facet wrapped stacked barchart all equal height with the percentages of each category projected in the middle of them. I just can't figure it out.
With the following code I got this figure:
ggplot(na.omit(plot_data), aes(x = cycle, y = percent, fill = response)) +
geom_col() +
facet_grid(~mut)+
geom_text(aes(label=percent(percent, accuracy = 1)),
position = position_stack(vjust = .5), size = 4, color = "white") +
labs(x="", y="Percentage")+
scale_y_continuous(labels = percent)+
theme_bw()+
#scale_fill_brewer(palette = "Accent")+
scale_fill_jco()+
ggtitle("Response by mutation status (%)")+
theme(strip.text = element_text(size=18))+
theme(axis.line = element_line(size=1, colour = "black"),
panel.grid.major = element_line(colour = "#d3d3d3"), panel.grid.minor = element_blank(),
panel.border = element_blank(), panel.background = element_blank()) +
theme(plot.title = element_text(size = 18, family = "serif", face = "bold"),
text=element_text(family="serif"),
axis.text.x=element_text(colour="black", size = 12),
axis.text.y=element_text(colour="black", size = 12))
And I want it to be just like this figure but then obviously retaining the facet wrap:
This is my data:
tibble [60 x 6] (S3: tbl_df/tbl/data.frame)
$ PID: num [1:60] 1 2 3 4 5 6 7 8 9 10 ...
$ mut: chr [1:60] "PP" "PN" "PP" "n/a" ...
$ C2 : chr [1:60] "n/a" "n/a" "n/a" "PR" ...
$ C4 : chr [1:60] "MR" "SD" "n/a" "n/a" ...
$ C8 : chr [1:60] "MR" "MR" "n/a" "n/a" ...
$ BE : chr [1:60] "MR" "MR" "n/a" "PR" ...
Your help is much appreciated!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…