empty factor level coord_polar

25 views
Skip to first unread message

Jonas Tundo

unread,
Apr 18, 2012, 9:27:53 AM4/18/12
to ggp...@googlegroups.com

Hello,

 

When I plot a polar graph of a factor variable with an empty level the empty level (“D” in the example) is not positioned well on the plot. How can I adjust this?

 

For example:

dat <- as.data.frame(c(rep("A",10),rep("B",8),rep("C",6)))

names(dat) <- "V1"

dat$V1 <- factor(dat$V1,levels=c("A","B","C","D"))

dat$colour <- as.factor(rep(c(1,2),12))

ggplot(data=dat,aes(V1)) + geom_bar(aes(fill=colour)) + scale_x_discrete(drop=FALSE)  +  coord_polar()

 

Greetings,

Jonas

Winston Chang

unread,
Apr 18, 2012, 11:47:02 AM4/18/12
to Jonas Tundo, ggp...@googlegroups.com
I think this is related to a bug that's in the process of being fixed. The fix should hopefully be in the next released version.

In the meantime, you can do this:
ggplot(data=dat,aes(V1)) + geom_bar(aes(fill=colour)) +
  scale_x_discrete(drop=FALSE, expand=c(0,0.5)) +
  scale_y_continuous(expand=c(0,0)) +
  coord_polar(expand=TRUE)

In the future all that stuff with expand won't be necessary and the code that you originally wrote should work.

-Winston


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages