所以我明白你的要求,你可以这么做,但是,这是非常武断的
library(tidyverse)
my_labs <- c(t = "12 14 18 20",
u = "11 15 17")
ggplot(df, aes(x=subj, y=mean*100, fill=time)) +
geom_bar(stat="identity", position="dodge") +
facet_wrap(~ group, scale="free", labeller = as_labeller(my_labs))
geom_text
标记列,使其始终位于正确的位置。从长远来看,它们也会更好看。
my_text <- data_frame(subj = as.factor(c(12,14,18,20,11,15,17)), group = c(rep("t", 4), rep("u", 3)), mean = c(rep(105, 7)))
ggplot(df, aes(x=subj, y=mean*100, fill=time)) +
geom_bar(stat="identity", position="dodge") +
geom_text(data = my_text, aes(x=subj, y=mean, label = subj), inherit.aes = FALSE)+
facet_wrap(~ group, scale="free")+
theme(strip.background = element_blank(),
strip.text = element_blank())
df <- df %>% mutate(subj = factor(subj, levels = c("12", "14", "18", "20", "11", "15", "17")))
my_labs <- levels(df$subj)
ggplot(df, aes(x=as.numeric(subj), y=mean*100, fill=time)) +
geom_bar(stat="identity", position="dodge") +
facet_wrap(~ group, scale="free")+
scale_x_continuous(breaks = 1:length(my_labs), labels = my_labs, sec.axis = dup_axis())+
xlab("subj")+
theme(strip.background = element_blank(),
strip.text = element_blank())
于2018年8月18日由
reprex
package
(第0.2.0版)。