labs(fill=NULL) indeces the error.
try labs(fill="")
the last example surpress the legend display for fill by
opts(lenend.position="none"), so there is no error.
this may be a bug.
probably labs(fill=NULL) should work and draw nothing, because
labs(fill="") draw something invisible.
--
Kohske Takahashi <takahash...@gmail.com>
Research Center for Advanced Science and Technology,
The University of Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
Denis
I want a series of bar plots to describe the abundance of different prey categories in the diet of a fish, according to fish size.
I used to do this with R base graphics. Here is one example:
<http://dl.dropbox.com/u/612902/Diet%20plot%20base%20graphics.pdf>
I think I advantageously reproduced this with ggplot2:
http://dl.dropbox.com/u/612902/Diet%20plot%20ggplot2.pdf
One of the things I I like about the ggplot2 version is the fact that the axes values are not repeated for each graphic, which increases the surface of the plot that is available to show data.
I am very much a beginner with ggplot2 and I did not manage to control the distance between tick labels and the axis. In base graphics, I did this by changing the mar and mgp parameters:
par(oma=c(1.4,1.4,0,0)+0.1, mar=c(1.8, 1.8, 0.2, 0.2)+0.1, xpd=NA, mgp=c(1.8,0.5,0), cex.lab=1.2)
My first question is: am I right to think that mar and mgp have no effect whatsoever with ggplot2?
Secondly, from what I found in the ggplot2 user guide, I should have been able to change the position of the tick labels with hjust and vjust. I can get this to work when I do not do facetting, but it does not seem to have any effect with facetting.
For instance, the figure above was obtained with this code (which should work for anyone because the data set is on my DropBox, but replace the quartz() with windows() if you are on Windows):
library(ggplot2)
load(url("http://dl.dropbox.com/u/612902/%20Data%20for%20diet%20plot.Rda"))
quartz(w=10,h=7)
a <- ggplot(thedataB, aes(x = Length_Class, y = value, fill = PreyNames)) + opts(title = "Cod Diet") +
labs(x = "Cod length (cm)", y = "Fullness Index")
theme_set(theme_bw())
b = a + geom_bar(stat = "identity") + facet_wrap(~ PreyNames, ncol=5)
c = b + opts(legend.position = "none", axis.text.x = theme_text(hjust=0.5, vjust=0.5), axis.text.y = theme_text(hjust=0.5, vjust=0.5) )
c
I tried to get the x tick labels a bit higher, closer to the x axis using vjust = 0 (or -1 or -5 for that matter) but only hjust has an effect on the position of the x tick labels (i.e. axis values). Similarly, I would have brought the y tick labels a bit closer to the y axis with a xjust = 1, but here only vjust seems to have an effect.
What am I missing?
Sincerely,
Denis
try this:
c + opts(axis.ticks.margin=unit(1, "mm"))
--
Kohske Takahashi <takahash...@gmail.com>
Research Center for Advanced Science and Technology,
The University of Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html
I thought I looked at all possible "options" and found none for this behaviour, but I was wrong.
Still, is is a feature or a bug (or incomplete knowledge of ggplot2 on my part) that vjust does not work for x tick labels on a facetted plot, while it clearly works on non-facetted plots? And same for hjust on y tick labels?
Denis
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
The following represents my understanding, and could well be wrong.
I'm sure someone will quickly correct me if that is the case.
The basic misunderstanding here is that vjust and hjust are not
intended to (v)ertically ad(just) or (h)orizontially ad(just) the
text. They are designed to set the (v)ertical (just)ification and
(h)orizontal (just)ification. Basically, they are continuous analogs
of aligning text left, center, right, top, middle, bottom. If you read
the help file you will see that they should be set to values between 0
and 1. See ?theme_text for reference.
Now, in reality it seems you can use them to adjust the position, by
passing values smaller than 0 or larger than 1, but that doing so
results in weird things happening. I wouldn't get too hung up on that,
because it's simply not how they were designed to work. If anything,
theme_text could return an error if vjust or hjust were set outside
the [0,1] interval.
HTH,
Ista
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
>
>
> Le 2011-04-26 à 09:31, Hadley Wickham a écrit :
>
>
> The ultimate would be to reproduce with a dataset like:
>
> df <- data.frame(x = c("a", "b"), y = 1:2, z = 3:4)
>
> Thanks!
>
> Hadley
>
>
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
You may be right, but in this case the analogy with basic R's adj parameter would be lost because adj is intended to "justify" text, but by using values outside the 0-1 interval you can also move text.
This said, there are reasons to think we should be able to use values outside the 0-1 interval with predictable results. For instance, the value of 7 is used in Hadley's own example. Furthermore, if we could ONLY use values within 0 and 1 to have predictable results, then we'd need another parameter to be able to control how far the axis text is from the axis. Finally, in my tests, vjust had no effect at all unless I also used a non-zero value for angle.
My feeling is that hjust and vjust are supposed to do what I wanted, but something is wrong with the implementation right now. This would explain why the example from <https://github.com/hadley/ggplot2/wiki/Axis-Attributes> is not repeatable.
Cheers,
Denis
dat <- data.frame(x=c("Long label for X value one", "Long label for X
value 2"), y=c(100000, 100001))
p1 <- ggplot(dat, aes(x=x, y=y)) + geom_point()
p1
p1 + opts(axis.text.x=theme_text(vjust=.5, hjust=.5),
axis.text.y=theme_text(vjust=.5, hjust=.5))
p1 + opts(axis.text.x=theme_text(vjust=1, hjust=.5),
axis.text.y=theme_text(vjust=1, hjust=.5))
p1 + opts(axis.text.x=theme_text(vjust=.5, hjust=1),
axis.text.y=theme_text(vjust=.5, hjust=1))
p1 + opts(axis.text.x=theme_text(angle = 45),
axis.text.y=theme_text(angle = 45))
p1 + opts(axis.text.x=theme_text(vjust=.5, hjust=.5, angle = 45),
axis.text.y=theme_text(vjust=.5, hjust=.5, angle = 45))
p1 + opts(axis.text.x=theme_text(vjust=1, hjust=.5, angle = 45),
axis.text.y=theme_text(vjust=1, hjust=.5, angle = 45))
p1 + opts(axis.text.x=theme_text(vjust=.5, hjust=1, angle = 45),
axis.text.y=theme_text(vjust=.5, hjust=1, angle = 45))
p1 + opts(axis.text.x=theme_text(vjust=.5, hjust=.5, angle = 90),
axis.text.y=theme_text(vjust=.5, hjust=.5, angle = 90))
p1 + opts(axis.text.x=theme_text(vjust=1, hjust=.5, angle = 90),
axis.text.y=theme_text(vjust=1, hjust=.5, angle = 90))
p1 + opts(axis.text.x=theme_text(vjust=.5, hjust=1, angle = 90),
axis.text.y=theme_text(vjust=.5, hjust=1, angle = 90))
Wow, that was boring and lame. Sorry. Anyway, it makes sense to me.
Now what is is you want to do? What is the problem with the way the
theme_text settings work?
Best,
Ista