Ggplot2 Marking a multilayer strip

What I would like to do is the geom_bar () label in the following example with the corresponding data labels. So far, I can only get one or the other:

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()

Multilayered Bar Graph

See how there is a data label on the inside of black. In the same plot, I would like to do the same inside violet.

+5
source share
2 answers

how it works for you:

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()
+6
source

You might want to consider a different approach.

If the main goal of the chart is to compare the lengths / positions of bars, then the inclusion of numbers in bars leads to the appearance of “fuzzy” bars, which makes it difficult to correctly evaluate the eye / brain by the length / position of the bar,

, ( ), , .

( ), ( ), , . , (ggplot2 ), 1- () , .

+3

All Articles