我们可以尝试一种解决方法:
# add a fake column
df_2$fake <-rownames(df_2)
library(ggplot2)
# we add as x the fake
ggplot(aes(x=fake, y=Genderity), data=df_2, position="stack")+
geom_bar(stat="identity",aes(fill=Subset),position="dodge")+
coord_flip()+
geom_hline(yintercept = 0, color =c("black")) +
scale_y_continuous(breaks=seq(-5,5,1), limits=c(-5,5))+
# to avoid riffle, we use the scales="free" option
facet_wrap(facets = .~Set, ncol = 2, nrow=1,scales="free")+
# last, we make blank the y axis
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())
而且,如果您想要模型中的订单并且还想要 x 轴空白,您可以试试这个:
# the reorder option:
ggplot(aes(x=reorder(fake,Genderity), y=Genderity), data=df_2, position="stack")+
geom_bar(stat="identity",aes(fill=Subset),position="dodge")+
coord_flip()+
geom_hline(yintercept = 0, color =c("black")) +
scale_y_continuous(breaks=seq(-5,5,1), limits=c(-5,5))+
facet_wrap(facets = .~Set, ncol = 2, nrow=1,scales="free")+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
# x-axis blank:
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
和:
+ ggtitle("Conveyed gender")
会给你标题。
编辑:
要添加标签,您必须:
p <- ggplot(aes(x=reorder(fake,Genderity), y=Genderity), data=df_2, position="stack")+
geom_bar(stat="identity",aes(fill=Subset),position="dodge")+
coord_flip()+
geom_hline(yintercept = 0, color =c("black")) +
scale_y_continuous(breaks=seq(-5,5,1), limits=c(-5,5))+
facet_wrap(facets = .~Set, ncol = 2, nrow=1,scales="free")+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
# x-axis blank:
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
p <- p + ggtitle("Conveyed gender") + geom_text(aes(label=Genderity), hjust=1)
p
或者你也可以使用:
+ geom_text(aes(label = Genderity), position = position_dodge(0.9))