An old code that used to work perfectly no longer works with 0.9.3. The issue is related to the use of facets, free scales and coord flip.
Here is a way to reproduce:
data set: d.csv:
"Priority","Owner","Project"
"Medium","owner7","Team4"
"Medium","owner1","Team1"
"Low","","Team3"
"High","owner6","Team3"
"Medium","","Team4"
"Medium","owner3","Team1"
"Medium","owner2","Team1"
"Medium","owner5","Team2"
"Low","owner4","Team2"
"Critical","","Team2"
"Medium","owner2","Team1"
"High","","Team4"
Code:
data <- read.csv(file="d.csv",head=TRUE)
attach(data)
p3 <- ggplot(data,aes(x=Owner,fill=Priority))+
geom_bar(aes(y=..count..)) +
facet_wrap(~ Project, nrow=2, scales="free") +
opts(legend.position="none")
This creates a faceted plot but I need the axes flipped. Previously, adding a coord_flip() did the trick but now the new ggplot does not permit using free scales and coord_flip together. Is there any other way to turn the facet axes around? The free scales are important to me. Thanks for any pointers.
Update per late 2016: This bug with
coord_flip
,facet_grid
andscales="free"
has been fixed in the development version ofggplot2
. You can install it withNote, try both
free_x
andfree_y
depending on your needs, because it is not always clear whatx
andy
mean when you have flipped the coordinates.It seems like what you are requesting (if I understand the question correctly) has been raised to the developers before and they will not implement it. See here:
https://github.com/hadley/ggplot2/issues/95
So I guess you need to find a workaround. Here's a quick idea that should work: Use
facet_grid
instead of "facet_wrap", then coord_flip() should work. Then save the picture as a pdf (or svg) and rearrange the plots in some kind of vector graphic software - I'd suggest Inkscape...This is the second or third time I have run into this problem myself. I have found that I can hack my own solution by defining a custom geom.
This is just copying the geom_bar code from the ggplot2 github and then switching the x and y references to make a horizontal barplot in the standard Cartesian coordinators.
Note that you must use
position='identity'
and possibly alsostat='identity'
for this to work. If you need to use a position other than identity then you will have to eddit the collide function for it to work properly.