I noticed similar (but not identical) problems with the date format, which apparently does not work using time zones when using format
used in date_format()
.
Your basic plot
library(ggplot2)
library(scales)
p <- ggplot(dfn, aes(as.POSIXct(p_date), length, colour = factor(supp))) +
geom_point(size=3) +
geom_line(size=1.3) +
labs(colour="Lines :", x = "", y = "") +
guides(colour = guide_legend(override.aes = list(size=5))) +
theme(axis.text.x=element_text(size=15))
p + scale_x_datetime(breaks = date_breaks("1 month"),
labels = date_format("%m/%Y"))
What produces
, , , -,
date_format()(date_breaks()(as.POSIXct(dfn$p_date[c(1,3)])))
#[1] "2015-01-01" "2015-02-01" "2015-03-01" "2015-03-31" "2015-04-30" "2015-05-31"
#[7] "2015-06-30" "2015-07-31" "2015-08-31"
, .
my_format <- function (format = "%Y-%m-%d") {
function(x) format(x, format)
}
p + scale_x_datetime(breaks = date_breaks("1 month"),
labels = my_format("%m/%Y"))
,
my_format()(date_breaks()(as.POSIXct(dfn$date2[c(1,3)])))
#[1] "2015-01-01" "2015-02-01" "2015-03-01" "2015-04-01" "2015-05-01" "2015-06-01"
#[7] "2015-07-01" "2015-08-01" "2015-09-01"
, POSIX , .
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8
[4] LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] datasets utils stats graphics grDevices grid methods base
other attached packages:
[1] scales_0.3.0 data.table_1.9.6 Hmisc_3.17-0 Formula_1.2-1 survival_2.38-3
[6] lattice_0.20-33 MASS_7.3-44 gridExtra_2.1.0 ggplot2_1.0.1.9003
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 digest_0.6.8 chron_2.3-47 plyr_1.8.3 gtable_0.1.2
[6] acepack_1.3-3.3 latticeExtra_0.6-26 rpart_4.1-10 labeling_0.3 proto_0.3-10
[11] splines_3.2.2 RColorBrewer_1.1-2 tools_3.2.2 foreign_0.8-66 munsell_0.4.2
[16] colorspace_1.2-6 cluster_2.0.3 nnet_7.3-11