I have a database that is being used to create a time series. The date column in the time series database is formatted as a POSIXct date format.
Database
data <- structure(list(TimeStep = c("1", "1", "1", "1", "10", "10", "10",
"10", "11", "11", "11", "11", "12", "12", "12", "12", "2", "2",
"2", "2", "3", "3", "3", "3", "4", "4", "4", "4", "5", "5", "5",
"5", "6", "6", "6", "6", "7", "7", "7", "7", "8", "8", "8", "8",
"9", "9", "9", "9"), Shelter = structure(c(1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("Low",
"High"), class = c("ordered", "factor")), Site_long = structure(c(2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), .Label = c("Hanauma Bay",
"Waikiki"), class = c("ordered", "factor")), mean = c(0, 0.00015328484505956,
7.04072939791738e-06, 0.000682330358210582, 2.66666666666667e-06,
6.00605206484062e-07, 0, 0.000386079421618121, 0, 0.000107757674499178,
3.38820905388829e-05, 0.000309370042627687, 2.66666666666667e-06,
0.000258419039004161, 3.40590905388829e-05, 0.000600512507641285,
0, 0.000252408374787308, 7.40825319693649e-05, 0.000656756473864922,
8.69852169224144e-05, 7.75576156462366e-05, 8.33333333333333e-08,
0.000665098673793383, 0, 2.04566422429192e-05, 5.31031263835315e-05,
0.000647037987463065, 0, 0.000198961690069793, 0, 0.000423723440028656,
8.16572939791738e-06, 0.00012785593538717, 2.34677162777718e-08,
0.000224655093601419, 3.33333333333333e-07, 7.42595319693649e-05,
0.00039116506393873, 2.13882406395912e-05, 2.66666666666667e-06,
0.000107081818106607, 4.16666666666667e-08, 3.77742205841092e-05,
1.88237465916921e-05, 0.00010916313850296, 0, 7.6903907646831e-05
), sd = c(0, 0.00015966459922941, 9.95709500353371e-06, 0.000482307005382674,
3.77123616632825e-06, 8.0011788810835e-07, 0, 0.000440508169853482,
0, 0.000152392364726523, 4.79165119616413e-05, 0.000309520641549238,
3.77123616632825e-06, 0.000184777835884834, 4.81668277621813e-05,
0.000477723602613157, 0, 0.000179807492264746, 0.000104768521446014,
0.000482423300574339, 0.000123015673497644, 0.000105040104106768,
1.17851130197758e-07, 0.000498359190138349, 0, 2.55445716349544e-05,
7.50991615360028e-05, 0.000105303327368202, 0, 0.000185382956021377,
0, 0.000316153398426712, 1.15480852612034e-05, 9.37823230585177e-05,
3.31883626379487e-08, 0.000297053654293301, 4.71404520791032e-07,
0.000104643588086737, 0.000406298601551981, 1.51238560888153e-05,
3.77123616632825e-06, 0.000145843975969992, 5.8925565098879e-08,
2.23804174757353e-05, 2.66207977246453e-05, 0.000145131278731618,
0, 5.83391012319395e-05), lower = c(0, 6.11024457144067e-05,
1.29199791728051e-06, 0.000403870278820852, 4.89342450859397e-07,
1.38656928401271e-07, 0, 0.000131751911172984, 0, 1.97739017018764e-05,
6.21747945920136e-06, 0.000130668216909489, 4.89342450859397e-07,
0.000151737505715775, 6.24995956437715e-06, 0.000324698657074341,
0, 0.000148596470725945, 1.35943979099095e-05, 0.000378229251414979,
1.59620847140065e-05, 1.69126832644878e-05, 1.52919515893562e-08,
0.000377370861213884, 0, 5.70847693314461e-06, 9.74460525480512e-06,
0.000586241083060471, 0, 9.19307905076825e-05, 0, 0.000241192190341779,
1.49843926373682e-06, 7.37106859241061e-05, 4.30640617478918e-09,
5.31510863314202e-05, 6.11678063574246e-08, 1.38435282185187e-05,
0.000156588456961325, 1.26564782555285e-05, 4.89342450859397e-07,
2.2878759320647e-05, 7.64597579467808e-09, 2.48528805299173e-05,
3.45422185932556e-06, 2.53715556594257e-05, 0, 4.32218118462899e-05
), upper = c(0, 0.000245467244404714, 1.27894608785542e-05, 0.000960790437600311,
4.84399088247394e-06, 1.06255348456685e-06, 0, 0.000640406932063258,
0, 0.00019574144729648, 6.15467016185644e-05, 0.000488071868345885,
4.84399088247394e-06, 0.000365100572292546, 6.18682215133886e-05,
0.000876326358208229, 0, 0.00035622027884867, 0.00013457066602882,
0.000935283696314864, 0.000158008349130822, 0.000138202548027985,
1.51374715077311e-07, 0.000952826486372883, 0, 3.52048075526939e-05,
9.64616475122579e-05, 0.00070783489186566, 0, 0.000305992589631903,
0, 0.000606254689715534, 1.48330195320979e-05, 0.000182001184850233,
4.26290263807544e-08, 0.000396159100871418, 6.05498860309242e-07,
0.000134675535720211, 0.000625741670916134, 3.01200030236539e-05,
4.84399088247394e-06, 0.000191284876892567, 7.56873575386553e-08,
5.06955606383012e-05, 3.41932713240586e-05, 0.000192954721346495,
0, 0.000110586003447372), Date_new = structure(c(17311, 17323,
17311, 17323, 18154, 18149, 18154, 18149, 18244, 18240, 18244,
18240, 18309, 18338, 18310.6666666667, 18338, 17419, 17414, 17419,
17414, 17503, 17498, 17503, 17498, 17596.3333333333, 17561, 17605.3333333333,
17561, 17671, 17666, 17671, 17666, 17775, 17771, 17775, 17771,
17873, 17869, 17873, 17869, 17977, 17974, 17977, 17974, 18050,
18051, 18050, 18051), class = "Date")), row.names = c(NA, -48L
), groups = structure(list(TimeStep = c("1", "1", "10", "10",
"11", "11", "12", "12", "2", "2", "3", "3", "4", "4", "5", "5",
"6", "6", "7", "7", "8", "8", "9", "9"), Shelter = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Low", "High"), class = c("ordered",
"factor")), .rows = structure(list(1:2, 3:4, 5:6, 7:8, 9:10,
11:12, 13:14, 15:16, 17:18, 19:20, 21:22, 23:24, 25:26, 27:28,
29:30, 31:32, 33:34, 35:36, 37:38, 39:40, 41:42, 43:44, 45:46,
47:48), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr",
"list"))), row.names = c(NA, -24L), class = c("tbl_df", "tbl",
"data.frame"), .drop = TRUE), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
When I plot these data using month only labels at three-month increments, I get labels at "Jul", "Oct", "Jan", and "Apr", when I actually want the month labels to be "Jun", "Sep", "Dec", and "Mar" instead. I have tried specifying the labels as a character vector of these month abbreviations to no avail.
Plot Code
urchin_time_series_plot <- ggplot(data = data, aes(x = Date_new, y = mean, fill = Shelter, shape = Site_long)) +
geom_point(aes(size = 3)) +
geom_line(aes(linetype = Shelter)) +
scale_linetype_manual(values=c("dashed", "solid")) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_manual(values = c(NA, "black"), guide = guide_legend(override.aes = list(shape = 21))) +
scale_y_continuous(labels = scientific) +
guides(size = FALSE) +
geom_errorbar(aes(ymin = lower, ymax = upper), width = 0) +
scale_x_date(date_breaks = "3 months", date_labels = "%b") +
labs(x = "Date", y = "Urchin biomass (Kg)") +
theme_bw() + theme(text = element_text(size = 14), panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), axis.title.x = element_blank(), axis.text = element_text(size = 16), legend.text = element_text(size = rel(1.5)), axis.text.y = element_text(angle = 90, hjust = .9), legend.title = element_text(size = rel(1.5)), legend.position = "none", axis.title.y = element_text(size = 18), axis.title = element_text(size = 16))
Output
Any suggestions to shift the months on the x-axis labels back one month to "Jun", "Sep", "Dec", and "Mar" would be greatly appreciated.