Edward Edward - 7 months ago 28
R Question

Time series: Available data graphs (ggplot)

I discovered the package nsRFA which I intended to use for precipitation data analysys and I found the function

consistencyplot()
which I think is amazing.

> library(nsRFA)
> data(hydroSIMN)
> head(annualflows)
cod anno dato
1 1 1956 1494
2 1 1957 1309
3 1 1958 1699
4 1 1959 1467
5 1 1960 1918
6 1 1961 1469
> y <- annualflows["anno"][,]
> cod <- annualflows["cod"][,]
> consistencyplot(y,cod)




But I couldn't make it work with other data but the example given in the package example manual (
vignette("nsRFA_ex01", package="nsRFA")
). So I tried to replicate the plot using ggplot but sadly I am lost.

I found it hard to give an meaningful example but using the data from the example above can anybody suggest any idea?

Answer Source

You could do it like this:

library(ggplot2)
library(dplyr)
annualflows %>% ggplot(aes(x = anno, y = cod)) + 
    geom_point(
        shape = 45,
        size = 5,
        col = "blue"
    ) + 
    scale_y_reverse(
        breaks = seq(10, 50, by = 10)
    ) +
    scale_x_continuous(breaks = seq(1920, 1980, by = 10)) +
    labs(
        x = "Year",
        y = "Code"
    ) + 
    theme(
        panel.background = element_blank(),
        panel.border = element_rect(fill = NA),
        text = element_text(size = 10),
        panel.grid.major.x = element_line(color = "grey80"),
        panel.grid.major.y = element_line(color = "grey80")
    )

enter image description here