Tornado chart / chart with ggplot2

I am having difficulty getting this for the correct conclusion ...

Here is what I have 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 have 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 
+4
source share
3 answers

Since 2012, ggplot forbids Error: Mapping a variable to y and also using stat="bin" . Decision:

 ggplot(dat, aes(variable, value, fill=Level)) + geom_bar(position="identity", stat="identity") 

It also helps a lot if you use an asymmetric example, otherwise how do you know if you are 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 the desired tornado plot:

your desired tornado plot

+5
source

You can also use + coord_flip() instead of + geom_bar(position="identity")

+1
source

If the minus values โ€‹โ€‹are just a trick to compare the two groups, you can use:

 scale_y_continuous(labels=abs) 
-1
source

All Articles