ggsave: y-axis label is moved around depending on width and height options of ggsave

59 views
Skip to first unread message

Marius Hofert

unread,
Aug 15, 2011, 8:18:18 AM8/15/11
to ggplot2
Dear ggplot2-expeRts,

The following plot looks fine, but when I specify widht and height and
save it
to a file it shifts the y axis label. Is this a bug or a feature?

library(ggplot2)
df <- data.frame(Year=rep(2001:2010,3), Number=sample(x=1:100,
size=3*10, replace=TRUE),
Group=rep(1:3, each=10))
p <- ggplot(df, aes(x=Year, y=Number, fill=Group)) +
geom_bar(stat="identity",
position="stack", binwidth=1) +
opts(aspect.ratio=1/2, title="My title",
legend.position="bottom", legend.direction="horizontal") +
labs(x="My xlab", y="My ylab")
p # looks fine
ggsave("barplot.pdf") # also fine
ggsave("barplot.pdf", width=15, height=5) # why does it move the y
axis label so much to the left?

Cheers,

Marius

Hadley Wickham

unread,
Aug 15, 2011, 8:34:55 AM8/15/11
to Marius Hofert, ggplot2
This is fixed in the development version of ggplot2.
Hadley

> --
> 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
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Marius Hofert

unread,
Aug 15, 2011, 8:40:19 AM8/15/11
to Hadley Wickham, ggplot2
Dear Hadley,

many thanks!
I wanted to install the latest version from R-forge, but it is not available for 2.14 (I'm using 2.14 already for other reasons). I think I have to try this kind of "install several R versions on the same system" (which I was hoping I don't have to do)

Cheers,

Marius

Marius Hofert

unread,
Aug 15, 2011, 3:45:47 PM8/15/11
to Hadley Wickham, ggplot2
Dear Hadley,

where can I get the "development version of ggplot2"? I looked on R-forge but couldn't find anything. I also found ggplot2 on github (but could only find older versions than the one on CRAN).

Thanks and cheers,

Marius

Brian Diggs

unread,
Aug 15, 2011, 4:48:00 PM8/15/11
to ggplot2
On 8/15/2011 12:45 PM, Marius Hofert wrote:
> Dear Hadley,
>
> where can I get the "development version of ggplot2"? I looked on
> R-forge but couldn't find anything. I also found ggplot2 on github (but
> could only find older versions than the one on CRAN).

It is on github, under the develop branch. Something of an outline is
at https://github.com/hadley/ggplot2/wiki/improving-docs, but that is
includes forking the repository if you want to make changes; if you just
want to use it, you don't have to do that.

install.packages(c("devtools","RCurl"))
library(devtools)
has_devel() # verifies that you can install source packages

dev_mode() # optional, but recommended. It will install the development
version in a separate library so that it doesn't overwrite the released
version.

install_github("ggplot2", branch="develop")

That should pull in the proper dependencies, but if not, you may need to
install "roxygen2" (from CRAN) and "scales" (from github) yourself.

>>>> To post: email ggplot2-/JYPxA39Uh5...@public.gmane.org
>>>> To unsubscribe: email ggplot2+unsubscribe-/JYPxA39Uh5...@public.gmane.org


>>>> More options: http://groups.google.com/group/ggplot2
>>>>
>>>
>>>
>>>
>>> --
>>> Assistant Professor / Dobelman Family Junior Chair
>>> Department of Statistics / Rice University
>>> http://had.co.nz/
>>
>


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

Marius Hofert

unread,
Aug 15, 2011, 5:09:38 PM8/15/11
to Hadley Wickham, ggplot2
Okay, I found the development version and downloaded the .tar.gz. I tried different ways of installing the package, but it did not work. For example:

install.packages("~/Downloads/hadley-ggplot2-ggplot2-0.8.3-508-g6f723ff.tar.gz", repos=NULL)
Installing package(s) into ‘/Users/mhofert/Library/R/2.13/library’
(as ‘lib’ is unspecified)
Warning messages:
1: In file.rename(file.path(tmpDir, pkgname), instPath) :
cannot rename file '/Users/mhofert/Library/R/2.13/library/file644327a9/hadley-ggplot2-ggplot2-0.8.3-508-g6f723ff' to '/Users/mhofert/Library/R/2.13/library/hadley-ggplot2-ggplot2-0.8.3-508-g6f723ff', reason 'No such file or directory'
2: unable to move temporary installation '/Users/mhofert/Library/R/2.13/library/file644327a9/hadley-ggplot2-ggplot2-0.8.3-508-g6f723ff' to '/Users/mhofert/Library/R/2.13/library/hadley-ggplot2-ggplot2-0.8.3-508-g6f723ff'

Why is there a renaming issue?

Cheers,

Marius

Marius Hofert

unread,
Aug 15, 2011, 5:28:50 PM8/15/11
to ggplot2
Dear Brian,

thanks for your reply, I just noticed it. In the meanwhile, I did the
following:
(1) downloaded the devel version from https://github.com/hadley/ggplot2/tree/develop/R
(2) install.packages(c("dichromat", "munsell")) # dependencies for
scales
(3) tar xvfz hadley-scales-d7dca89.tar.gz
(4) R CMD INSTALL hadley-scales-d7dca89
(5) install.packages(c("reshape2", "scales", "memoise")) #
dependencies for ggplot2
(6) tar xvfz hadley-ggplot2-ggplot2-0.8.3-508-g6f723ff.tar.gz
(7) R CMD INSTALL hadley-ggplot2-6f723ff/

Apparently it worked, the devel version indeed puts the y-axis label
in the correct spot, thanks a ton :-)))

Marius

On Aug 15, 11:09 pm, Marius Hofert <marius.hof...@googlemail.com>
wrote:
> Okay, I found the development version and downloaded the .tar.gz. I tried different ways of installing the package, but it did not work. For example:
>
> install.packages("~/Downloads/hadley-ggplot2-ggplot2-0.8.3-508-g6f723ff.tar .gz", repos=NULL)
> Installing package(s) into ‘/Users/mhofert/Library/R/2.13/library’
> (as ‘lib’ is unspecified)
> Warning messages:
> 1: In file.rename(file.path(tmpDir, pkgname), instPath) :
>   cannot rename file '/Users/mhofert/Library/R/2.13/library/file644327a9/hadley-ggplot2-ggplot2- 0.8.3-508-g6f723ff' to '/Users/mhofert/Library/R/2.13/library/hadley-ggplot2-ggplot2-0.8.3-508-g6f 723ff', reason 'No such file or directory'

Matthieu Stigler

unread,
Aug 16, 2011, 12:42:05 PM8/16/11
to Brian Diggs, ggplot2
useful infos about how to use the dev version!! If I can make a small
suggestion, would be very nice to have such infos on the ggplto2 page,
had needed so long time to find this :-) Or did I miss it?

Thanks!

Mat

Le 15/08/2011 22:48, Brian Diggs a �crit :

Reply all
Reply to author
Forward
0 new messages