我有这个df:
df <- data.frame(
id = c(rep(1:3,20), rep(4:6,20)),
type = rep(c("A","B","C","D"), each=3, times=10),
timing = rep(c("T0","T1", "T2", "T3", "T4"), each=12, times=2),
group = rep(c("Case","Control"),each=60),
percentage = runif(120, min=15, max=25)
)
scale="free"
或scale="free_y"
无法制作此条形图:
require(scales)
ggplot(df, aes(x=id, y=percentage, fill=type)) +
facet_grid(group ~ timing,scale="free") +
geom_bar(position="stack",aes(width = 0.5),stat = "identity") +
scale_y_continuous(labels = percent_format())+
coord_flip()