I'm having a spot of difficulty getting this to output right...
Here's what I've tried so far:
sample data:
dat <- data.frame(
variable=c("A","B","A","B"),
Level=c("Top-2","Top-2","Bottom-2","Bottom-2"),
value=c(.2,.3,-.2,-.3)
)
This is the closest I've got so far:
ggplot(dat, aes(variable, value, fill=Level)) + geom_bar(position="dodge")
## plots offset, as expected
ggplot(dat, aes(variable, value, fill=Level)) + geom_bar(position="stack")
# or geom_bar(), default is stack but it overplots
Since 2012, ggplot forbids Error: Mapping a variable to y and also using stat="bin"
. The solution is:
ggplot(dat, aes(variable, value, fill=Level)) +
geom_bar(position="identity", stat="identity")
It also seriously helps if you use a non-symmetric example, otherwise how do you know if you're not looking at the top series mirrored twice?!
dat <- data.frame(
variable=c("A","B","A","B"),
Level=c("Top-2","Top-2","Bottom-2","Bottom-2"),
value=c(.8,.7,-.2,-.3)
)
gives your desired tornado plot:
You could also use + coord_flip()
instead of + geom_bar(position="identity")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With