Reputation: 914
Here is one dataset.
df <- structure(list(
day = c(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, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100),
hour = structure(
c(-2209041420, -2209041360, -2209041360, -2209041300, -2209041240, -2209041180,
-2209041120, -2209041060, -2209041000, -2209040880, -2209040820,
-2209040760, -2209040640, -2209040580, -2209040520, -2209040400,
-2209040280, -2209040220, -2209040100, -2209040040, -2209039920,
-2209039800, -2209039680, -2209039560, -2209039440, -2209039320,
-2209039200, -2209039080, -2209038960, -2209038840, -2209038720,
-2209038600, -2209038480, -2209038360, -2209038240, -2209038060,
-2209037940, -2209037820, -2209037640, -2209037520, -2209037400,
-2209037220, -2209037100, -2209036980, -2209036800, -2209036680,
-2209036500, -2209036380, -2209036200, -2209036080, -2209035900,
-2209035780, -2209035600, -2209035480, -2209035300, -2209035120,
-2209035000, -2209034820, -2209034700, -2209034520, -2209034340,
-2209034220, -2209034040, -2209033920, -2209033740, -2209033560,
-2209033440, -2209033260, -2209033080, -2209032960, -2209032780,
-2209032600, -2209032480, -2209032300, -2209032120, -2209032000,
-2209031820, -2209031640, -2209031520, -2209031340, -2209031220,
-2209031040, -2209030860, -2209030740, -2209030560, -2209030380,
-2209030260, -2209030080, -2209029900, -2209029780, -2209029600,
-2209029420, -2209029300, -2209029120, -2209029000, -2209028820,
-2209028640, -2209028520, -2209028340, -2209028220),
class = c("POSIXct", "POSIXt"), tzone = "UTC")),
class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -100L))
I want to create a line graph to show how daylength changes over days. So, x-axis will be day, and y-axis will be hour. But I want to convert time format to numeric. For example, 06:30 AM will be 6.5, and 06:45 will be 6.75 as ratio like a below graph.
Could you tell me how to do it?
Upvotes: -3
Views: 64
Reputation: 66520
library(tidyverse); library(lubridate)
df |>
mutate(hour_dec = hour(hour) + minute(hour)/60) |>
ggplot(aes(day, hour_dec)) +
geom_point() +
geom_path()
Upvotes: 3