我想要做的是在下面的示例中标记geom_bar()和它们各自的数据标签.到目前为止,我只能出现一个或另一个:
dput():
x <- structure(list(variable = c("a", "b", "c"), f = c(0.98, 0.66,
0.34), m = c(0.75760989010989, 0.24890977443609, 0.175125)), .Names = c("variable",
"f", "m"), row.names = c(NA, 3L), class = "data.frame")
ggplot(x, aes(variable, f, label=paste(f*100,"%", sep=""))) +
geom_bar() +
geom_text(size=3, hjust=1.3, colour="white") +
geom_bar(aes(variable, m, label=paste(m*100,"%",sep="")), fill="purple") +
coord_flip()
Run Code Online (Sandbox Code Playgroud)

看看黑色里面有一个数据标签.在同一个情节中,我想在紫色的内部做同样的事情.
这对你有什么用处:
ggplot(x, aes(variable, f, label=paste(f*100,"%", sep=""))) +
geom_bar() +
geom_text(size=3, hjust=1.3, colour="white") +
geom_bar(aes(variable, m, label=paste(m*100,"%",sep="")), fill="purple") +
geom_text(aes(y=m,label=paste(round(m*100),"%",sep="")),size=3, hjust=1.3, colour="white") +
coord_flip()
Run Code Online (Sandbox Code Playgroud)