Good afternoon everyone,
I am currently trying to plot the effort in sampling for my masters thesis, which looks something similar to this:
fig.1
enter image description here
So i have data for 3 years, and i want to reflect the exact days of the month when each deployment started and finished. But in R, i only manage to plot the following:
fig.2
enter image description here
The thing is, i would like my plot to show only the 12 months in the x axis and overlap the years on the y axis, so that the figure is “slimmer”. I am guessing i have to somehow take out the year of the POSIXct dates, but i do not manage to represent the intervals as precisely then.
I did a subset of my data for this question and my script looks like this:
library(ggplot2)
library(scales)
library(tidyverse)
library(dplyr)
library(lubridate)
Deployment3 <- seq(from = as.Date(“2021-12-15”), to = as.Date(“2021-12-31”), by = “day”);
deploy3 <- data.frame(count=1:length(Deployment3));
deploy3$day <- Deployment3;
deploy3$year <- format(Deployment3, “%Y”);
deploy3$id <- “Deployment 3”
deploy3$start <- as.Date(“2021-12-15”); deploy3$end <- as.Date(“2021-12-31”);
Deployment7 <- seq(from = as.Date(“2022-12-17”), to = as.Date(“2022-12-31”), by = “day”);
deploy7 <- data.frame(count=1:length(Deployment7)); deploy7$day <- Deployment7;
deploy7$year <- format(Deployment7, “%Y”); deploy7$id <- “Deployment 7”;
deploy7$start <- as.Date(“2022-12-17”); deploy7$end <- as.Date(“2022-12-31”);
Deployment7b <- seq(from = as.Date(“2023-01-01”), to = as.Date(“2023-01-31”), by = “day”);
deploy7b <- data.frame(count=1:length(Deployment7b)); deploy7b$day <- Deployment7b;
deploy7b$year <- format(Deployment7b, “%Y”); deploy7b$id <- “Deployment 7”
deploy7b$start <- as.Date(“2023-01-01”); deploy7b$end <- as.Date(“2023-01-31”)
deployments <- bind_rows(deploy3,deploy7,deploy7b)
deployments$start <- as.Date(deployments$start)
deployments$end <- as.Date(deployments$end)`ggplot(deployments) +
geom_tile(aes(x = start, y = as.factor(year), width = end – start), height = 0.4) +
scale_x_date(date_labels = “%b”, date_breaks = “1 month”, expand = c(0, 0)) +
labs(x = “Month”, y = “Year”) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
If somebody would have any idea or suggestion to make the fig.2 more similar to fig.1 would be great.
Thank you and cheers!
Angaro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.