Tag Archives: R

Moving label titles in ggplot

Looking to create a small multiples plot in ggplot with a wordy y axis title. Here is the code:
ggplot(myData) +
aes(x=x, y=y) +
geom_point() +
facet_wrap(~a_third_variable) +
labs(x="XXX", y="Many, many words about YYY")

Want to see some of the wonderful things that one can adjust with the axes, go read
formats for axes. But, I had the y-axis title overlapping the scale ticks on the y-axis and there was nothing I found in the cookbook to deal with this.

So, to adjust the position use a theme method:
theme(axis.title.y = element_text(vjust=0.5))

Remember that this is adjusting from the perspective of the axis, so for the y-axis I want to shift it vertically.

Need to be able to silence warns on lubridate functions

The lubridate package in R is excellent. It is intuitive for working with all kinds of date methods and very comprehensive. All praise to Hadley for continuing to maintain this excellent addition to the community.

In recent work, I have noticed that methods will correctly handle NA values in the input object, but I don’t see a way to turn off the warnings when irrelevant. A long time ago, NA was breaking methods, but Hadley fixed that with b8e90c.

And it works.


> test <- c("1/1/15", "2/2/15", "3/3/15", NA, "5/5/15") > test
[1] "1/1/15" "2/2/15" "3/3/15" NA "5/5/15"
> is.na(test)
[1] FALSE FALSE FALSE TRUE FALSE
> dmy(test)
[1] "2015-01-01 UTC" "2015-02-02 UTC" "2015-03-03 UTC" NA "2015-05-05 UTC"

In addition, in the wild, I am using the method on a vector and getting warnings that I would like to ignore. I haven’t seen a param to pass to ignore warnings, so it would be a nice addition.