r - plotting julian dates across 2 calendar years -
i'm sure flagged duplicate cannot seem find solution.
i have dataset consisting of nitrogen measured in atmosphere across time. measurements collected daily november february of each year (~20 years). dates in julian format. default specs in ggplot2 treats feb first month should nov. how can address while keeping in mind x-axis should true (e.g., nov - dec - jan - feb). in advance.
structure(list(nitro = c(36, 51, 23, 7, 26, 62, 45, 25, 31, 70, 23, 63, 41, 61, 6, 24, 2, 6, 47, 22, 6, 48, 16, 25, 61, 9, 63, 3, 22, 27, 52, 9, 34, 48, 31, 16, 51, 63, 21, 42, 4, 9, 20, 28, 23, 0, 23, 70, 47, 2, 52.0898926784594, 55.8022284640568, 41.3593089128863, 57.9928202206287, 35.4624211011211, 65.2484486428607, 39.236626265918, 40.8906848288849, 65.7044590718657, 39.9377208120021, 51.1368297792738, 46.3981830973577, 36.3795615108741, 59.4071137999101, 42.77053802297, 51.4293854584156, 45.3589706700315, 53.9652146584217, 54.6980728446628, 43.1278297603877, 48.2879709803009, 60.0627232974633, 49.5233404192228, 55.4231572422576, 35.9842318889366, 55.649768270307, 61.8309485366259, 63.1600858734154, 52.9116478602541, 48.5690637010561, 49.4065375720883, 44.7880773761964, 48.5893427534388, 43.5882970429564, 33.0365374509187, 40.2149387649389, 67.3129711280128, 55.491540487927, 63.5614232930341, 53.6421935293565, 47.0292298358771, 62.5727076637489, 32.2728901281264, 61.7219468394218, 40.0865833610807, 24.1288862068719, 62.8734959914056, 52.3161174228334, 32.6827415750796, 50.3593375610126), juliandate = c(323l, 346l, 318l, 314l, 324l, 325l, 311l, 342l, 341l, 348l, 328l, 345l, 328l, 328l, 326l, 312l, 340l, 331l, 326l, 320l, 359l, 323l, 312l, 337l, 347l, 351l, 352l, 320l, 326l, 345l, 352l, 342l, 312l, 323l, 333l, 348l, 340l, 330l, 338l, 323l, 356l, 345l, 359l, 334l, 320l, 349l, 358l, 355l, 321l, 324l, 6l, 52l, 46l, 21l, 47l, 1l, 43l, 14l, 48l, 2l, 60l, 21l, 27l, 26l, 37l, 51l, 2l, 1l, 43l, 57l, 23l, 49l, 10l, 38l, 58l, 20l, 3l, 45l, 1l, 17l, 30l, 42l, 5l, 58l, 1l, 4l, 7l, 38l, 56l, 53l, 14l, 46l, 54l, 36l, 52l, 6l, 32l, 35l, 46l, 3l)), .names = c("nitro", "juliandate"), row.names = c(na, 100l), class = "data.frame") ggplot(d,aes(juliandate,nitro))+geom_point() #plot - should start @ julian 305, end @ julian 60
the best solution see map them single year , plot year using ggplot2
functionality make date julian date.
so there 2 parts solution, mapping, , display. in application realize these separate columns in dataframe.
the solution presented below uses wrapper function (j2d
)for mapping wraps date @ mid-year (180 days). uses ggplot2
function scale_x_date
convert date on output julian format:
library(ggplot2) j2d <- function(n){ n <- ifelse( n<180, n+365, n ) # wrap @ midyear d <- as.date("2015-01-01") + n return(d) } df <- structure( list( nitro = c(36, 51, 23, 7, 26, 62, 45, 25, 31, 70, 23, 63, 41, 61, 6, 24, 2, 6, 47, 22, 6, 48, 16, 25, 61, 9, 63, 3, 22, 27, 52, 9, 34, 48, 31, 16, 51, 63, 21, 42, 4, 9, 20, 28, 23, 0, 23, 70, 47, 2, 52.0898926784594, 55.8022284640568, 41.3593089128863, 57.9928202206287, 35.4624211011211, 65.2484486428607, 39.236626265918, 40.8906848288849, 65.7044590718657, 39.9377208120021, 51.1368297792738, 46.3981830973577, 36.3795615108741, 59.4071137999101, 42.77053802297, 51.4293854584156, 45.3589706700315, 53.9652146584217, 54.6980728446628, 43.1278297603877, 48.2879709803009, 60.0627232974633, 49.5233404192228, 55.4231572422576, 35.9842318889366, 55.649768270307, 61.8309485366259, 63.1600858734154, 52.9116478602541, 48.5690637010561, 49.4065375720883, 44.7880773761964, 48.5893427534388, 43.5882970429564, 33.0365374509187, 40.2149387649389, 67.3129711280128, 55.491540487927, 63.5614232930341, 53.6421935293565, 47.0292298358771, 62.5727076637489, 32.2728901281264, 61.7219468394218, 40.0865833610807, 24.1288862068719, 62.8734959914056, 52.3161174228334, 32.6827415750796, 50.3593375610126), juliandate = c(323l, 346l, 318l, 314l, 324l, 325l, 311l, 342l, 341l, 348l, 328l, 345l, 328l, 328l, 326l, 312l, 340l, 331l, 326l, 320l, 359l, 323l, 312l, 337l, 347l, 351l, 352l, 320l, 326l, 345l, 352l, 342l, 312l, 323l, 333l, 348l, 340l, 330l, 338l, 323l, 356l, 345l, 359l, 334l, 320l, 349l, 358l, 355l, 321l, 324l, 6l, 52l, 46l, 21l, 47l, 1l, 43l, 14l, 48l, 2l, 60l, 21l, 27l, 26l, 37l, 51l, 2l, 1l, 43l, 57l, 23l, 49l, 10l, 38l, 58l, 20l, 3l, 45l, 1l, 17l, 30l, 42l, 5l, 58l, 1l, 4l, 7l, 38l, 56l, 53l, 14l, 46l, 54l, 36l, 52l, 6l, 32l, 35l, 46l, 3l)), .names = c("nitro", "juliandate"), row.names = c(na, 100l), class = "data.frame") df$juliandate<-j2d(df$juliandate) ggplot(df,aes(juliandate,nitro))+ geom_point() + scale_x_date(labels = date_format("%j"))
Comments
Post a Comment