I have the following data: year and values for 12 months.
How to plot the values with respect to time (denoted by years) with the spacing that there will be 12 values between the two years? Thank you
1847 0.031 0.099 -1.585 1.170 1.763 -0.260 0.746 1.129 -0.324 0.445 2.459 1.760
1848 -0.792 1.770 0.757 -1.023 0.691 -1.780 1.867 2.641 -2.546 -2.436 -0.842 2.548
1849 2.419 2.767 -0.562 -0.990 -0.517 -3.210 1.203 0.701 -2.234 -0.078 0.802 -1.238
1850 -0.163 4.134 -2.216 0.965 -1.157 0.403 0.305 0.148 -2.077 -2.701 2.390 2.358
1851 3.293 1.028 1.504 -1.658 -1.534 -1.621 -5.395 4.679 1.852 0.777 -1.769 1.742
1852 1.464 0.411 -2.502 -1.597 0.245 0.093 -1.134 2.943 -2.021 -1.646 -0.930 1.029
Something like this
>Solution :
Alternatively, if you wanted to put all values in a single line:
dat <- import("https://quantoid.net/files/test.txt")
names(dat) <- c("year", paste0("month_", 1:12))
dat <- dat %>%
pivot_longer(-year, names_pattern="month_(\\d+)", names_to="month", values_to="val") %>%
mutate(month = as.numeric(month),
yrmo = year + (month - 1)/12)
ggplot(dat, aes(x=yrmo, y=val)) +
geom_line() +
scale_x_continuous(breaks=1847:1852)

