Hi there, I'm trying to find out the command to stop clipping to plot region in ggplot. I have a bar chart (axis flipped) with labels on the bars, but the labels are clipped at the plot region box. I know it's possible to turn this off for base and lattice, but how about ggplot? par(xpd=NA) The ggplot2 manual doesn't seem to mention it, and a search for ggplot and clip on this list hasn't yielded anything. It's possible this is obvious if you understand grid? -Alex
Could you please give a reproducible example? Thanks, Hadley On Thu, Jul 16, 2009 at 5:41 PM, Alex Brown<alex at transitive.com> wrote:> Hi there, > > ? ? ? ?I'm trying to find out the command to stop clipping to plot region in > ggplot. > > ? ? ? ?I have a bar chart (axis flipped) with labels on the bars, but the > labels are clipped at the plot region box. > > ? ? ? ?I know it's possible to turn this off for base and lattice, but how > about ggplot? > > ? ? ? ?par(xpd=NA) > > ? ? ? ?The ggplot2 manual doesn't seem to mention it, and a search for > ggplot and clip on this list hasn't yielded anything. > > ? ? ? ?It's possible this is obvious if you understand grid? > > -Alex > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- http://had.co.nz/
On Fri, Jul 17, 2009 at 3:39 AM, Alex Brown<fishtank at compsoc.man.ac.uk> wrote:> > Sure thing, an example.: > > ggplot > (data.frame(name=letters[1:3],value=c(1,4,9),type=c("fun","fun","not > fun")),aes(x=name,y=value,fill=type,label=paste("value is ",value))) + > geom_bar() + coord_flip() + geom_text(hjust=0) > > I'd like the option to allow the text " value is 9 " to spill out of the > plot region into the unused border partially occupied by the legend.Ah ok. Unfortunately, there's currently no way for ggplot2 to figure out how to increase the range of the x axis to avoid clipping text within the plot. This means you have to extend the y axis yourself, e.g. with + ylim(0, 12)> Also, is it possible to move each label right by one em (1 nominal font > height)? ?I think you can do that in grid graphics, but I can't see how to > do it here. ?I suppose I could always add an em space to the start of the > text, but I was thinking of something like x = value + unit(1,"char")You can't do it with ems, but you can do it with data units: df <- data.frame( name = letters[1:3], value = c(1,4,9), type = c("fun","fun","not fun") ) ggplot(df, aes(name, value, fill = type)) + geom_bar() + geom_text(aes(label=paste("value is ",value), y = value + 0.5), hjust = 0) coord_flip() + Hadley PS. You might also want to join the ggplot2 mailing list: http://groups.google.com/group/ggplot2 -- http://had.co.nz/