Hi all, I cannot for the life of me get my axis titles to adjust vertically in a ggplot. I've seen several posts about this and have tried everything: keeping vjust within 0 and 1, adjusting the margins, etc. hjust is behaving just as it should but vjust just mocks me in silence. No error message is produced. Here's a sample code: x=data.frame(sample(1:10)) x[,2]=sample(1:10) ggplot(data=x,aes(x=V2,y=V2))+theme(axis.title.y=element_text(vjust=.1,hjust=0.6), plot.margin=unit(c(1,1,2,2),'cm')) No matter what I put into vjust, nothing happens. Am I missing something obvious?? Thanks ahead of time for any help, Ryan -- Ryan Utz, Ph.D. Assistant professor of water resources *chatham**UNIVERSITY* Home/Cell: (724) 272-7769 [[alternative HTML version deleted]]
That looks to me like it might be buggy. At least I would have expected vjust to do _something_. In terms of the practical issue, you can adjust the distance between the title and the axis with margin, e.g. ggplot(data=x,aes(x=V2,y=V2))+theme(axis.title.y=element_text(margin margin(0, 5, 0, 0))) Best, Ista On Tue, Dec 22, 2015 at 12:59 PM, Ryan Utz <utz.ryan at gmail.com> wrote:> Hi all, > > I cannot for the life of me get my axis titles to adjust vertically in a > ggplot. I've seen several posts about this and have tried everything: > keeping vjust within 0 and 1, adjusting the margins, etc. hjust is behaving > just as it should but vjust just mocks me in silence. No error message is > produced. > > Here's a sample code: > > x=data.frame(sample(1:10)) > x[,2]=sample(1:10) > > ggplot(data=x,aes(x=V2,y=V2))+theme(axis.title.y=element_text(vjust=.1,hjust=0.6), > plot.margin=unit(c(1,1,2,2),'cm')) > > No matter what I put into vjust, nothing happens. Am I missing something > obvious?? > > Thanks ahead of time for any help, > Ryan > > > -- > > Ryan Utz, Ph.D. > Assistant professor of water resources > *chatham**UNIVERSITY* > Home/Cell: (724) 272-7769 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Are you sure it is not working for you? Your example code did not work for me at all until I removed the plot .margin parameter (unit wasn't recognized). Once I did that hjust and vjust worked as expected. However, values between .1 and .9 for vjust don't really move the axis title very much so it may not be real noticeable. Try a value like 2 or 3, just to make sure you easily see the change in position before concluding that nothing is happening. Dan Daniel Nordlund, PhD Research and Data Analysis Division Services & Enterprise Support Administration Washington State Department of Social and Health Services -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ryan Utz Sent: Tuesday, December 22, 2015 10:00 AM To: r-help at r-project.org Subject: [R] vjust unresponsive (ggplot2) Hi all, I cannot for the life of me get my axis titles to adjust vertically in a ggplot. I've seen several posts about this and have tried everything: keeping vjust within 0 and 1, adjusting the margins, etc. hjust is behaving just as it should but vjust just mocks me in silence. No error message is produced. Here's a sample code: x=data.frame(sample(1:10)) x[,2]=sample(1:10) ggplot(data=x,aes(x=V2,y=V2))+theme(axis.title.y=element_text(vjust=.1,hjust=0.6), plot.margin=unit(c(1,1,2,2),'cm')) No matter what I put into vjust, nothing happens. Am I missing something obvious?? Thanks ahead of time for any help, Ryan -- Ryan Utz, Ph.D. Assistant professor of water resources *chatham**UNIVERSITY* Home/Cell: (724) 272-7769 [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Hi Dan, Chances are that you haven't yet upgraded to ggplot2 version 2.0. unit (as well as arrow and alpha) are now re-exported from ggplot2. Using the latest release I also see that vjust doesn't seem to do anything. Best, Ista On Tue, Dec 22, 2015 at 1:37 PM, Nordlund, Dan (DSHS/RDA) <NordlDJ at dshs.wa.gov> wrote:> Are you sure it is not working for you? Your example code did not work for me at all until I removed the plot .margin parameter (unit wasn't recognized). Once I did that hjust and vjust worked as expected. However, values between .1 and .9 for vjust don't really move the axis title very much so it may not be real noticeable. Try a value like 2 or 3, just to make sure you easily see the change in position before concluding that nothing is happening. > > Dan > > Daniel Nordlund, PhD > Research and Data Analysis Division > Services & Enterprise Support Administration > Washington State Department of Social and Health Services > > > -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ryan Utz > Sent: Tuesday, December 22, 2015 10:00 AM > To: r-help at r-project.org > Subject: [R] vjust unresponsive (ggplot2) > > Hi all, > > I cannot for the life of me get my axis titles to adjust vertically in a ggplot. I've seen several posts about this and have tried everything: > keeping vjust within 0 and 1, adjusting the margins, etc. hjust is behaving just as it should but vjust just mocks me in silence. No error message is produced. > > Here's a sample code: > > x=data.frame(sample(1:10)) > x[,2]=sample(1:10) > > ggplot(data=x,aes(x=V2,y=V2))+theme(axis.title.y=element_text(vjust=.1,hjust=0.6), > plot.margin=unit(c(1,1,2,2),'cm')) > > No matter what I put into vjust, nothing happens. Am I missing something obvious?? > > Thanks ahead of time for any help, > Ryan > > > -- > > Ryan Utz, Ph.D. > Assistant professor of water resources > *chatham**UNIVERSITY* > Home/Cell: (724) 272-7769 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.