Graphic highlighting gap data over a given period

Hello everyone,

I get a dataset with some gap for specific years. I am now looking for how to make with R a graphic to show the years for which there is no data.
Below is a sample of graphic and I am triying to replicate it.

Screenshot (8)

Could someone tell me how to proceed ?

Looking for to hearing from you all.

Hi,

This really does not give us much to go on. Are the red lines in your plot where the data is missing or where there is data?

It would help to have some sample data. A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here between
```

```

Something like this may be of help Using Line Segments to Compare Values in R

Hello dear,

I understand and appreciate your kind feedback. In fact, from 1998 to 2021 is my period of dateset. Unfortunately, for some of the years , there is missing for certain stations . A particular case of this situation is shown below :
''
Years A B C D E
1998 20 - 15 25 10
1999 15 12 - - 05
2000 - 24 - 18 17 ''

My concern is now to make a figure that can allow the viewer to easily identify for which year there is no data.
That's what has been down in this figure I previously attached to my message. You can see that, for some years and certain stations, the lines were interrupted indicating that there is no data.

HI @Dany2 ,

As @jrkrideau says, it's important for you to share your data so that folks here can help. Have you already imported it into RStudio?

Hello @dromano

Thanks for your reply and sorry for my late feedback.
I didn't yet import my data in R, but you can see what it looks like here.

Again my problem is to make a figure which will represent for each area a line with gap for the year that don't get data (where the number 0 is). That is what my last Screenshot was hightlighting.

Could those information help now?

Could those information help now?

Perhaps but it is not ideal. We really need to see what the data looks like in R.

If your data is is an Excel file you can read in the data with

library(readxl)
dat1 <- read_excel("YourData_name")

Then do dput(dat1) and paste it here.

You may have to install {readxl) before doing this.

install.packages("readxl)

Hello @jrkrideau,
That's what it looks like

structure(list(Communes = c("ARRADON", "AURAY", "BADEN", "BELZ",
"BRANDERION", "CAMORS", "ERDEVEN", "KERVIGNAC", "LOCQUELTAS",
"MERLEVENEZ", "MEUCON", "NOSTANG", "PLESCOP", "PLOUHINEC", "PLUNERET",
"SAINT-AVE", "SAINTE-HELENE", "SENE", "SULNIAC", "THEIX-NOYALO",
"VANNES"), 1998 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), 1999 = c(5200, 1500, 41900, 0, 0,
0, 31200, 0, 0, 0, 22100, 0, 15600, 47800, 14800, 0, 0, 0, 7800,
10400, 0), 2000 = c(6500, 5200, 48300, 0, 0, 52000, 27300,
0, 0, 0, 31200, 0, 13000, 59300, 17800, 0, 0, 0, 9100, 10400,
0), 2001 = c(6500, 5200, 33500, 0, 0, 3900, 0, 0, 0, 0, 26000,
14400, 14900, 51500, 19100, 0, 0, 0, 7800, 10400, 0), 2002 = c(0,
5200, 7800, 0, 0, 5200, 24700, 0, 0, 0, 32500, 6300, 11700, 58000,
10000, 0, 0, 0, 7800, 10000, 0)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -21L))

The screenshot of my R environment is as below

Thanks for the data. However for some reason I am having a problem reading it it. It looks like there are some strange characters in it. Also I do not understand why we are getting pure numeric character names.

I did some hand editing and I think I now have a clean version of the data set.

structure(list(Communes = c("ARRADON", "AURAY", "BADEN", "BELZ", 
"BRANDERION", "CAMORS", "ERDEVEN", "KERVIGNAC", "LOCQUELTAS", 
"MERLEVENEZ", "MEUCON", "NOSTANG", "PLESCOP", "PLOUHINEC", "PLUNERET", 
"SAINT-AVE", "SAINTE-HELENE", "SENE", "SULNIAC", "THEIX-NOYALO", 
"VANNES"), Y1998 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0), Y1999 = c(5200, 1500, 41900, 0, 0, 0, 31200, 
0, 0, 0, 22100, 0, 15600, 47800, 14800, 0, 0, 0, 7800, 10400, 
0), Y2000 = c(6500, 5200, 48300, 0, 0, 52000, 27300, 0, 0, 0, 
31200, 0, 13000, 59300, 17800, 0, 0, 0, 9100, 10400, 0), Y2001 = c(6500, 
5200, 33500, 0, 0, 3900, 0, 0, 0, 0, 26000, 14400, 14900, 51500, 
19100, 0, 0, 0, 7800, 10400, 0), Y2002 = c(0, 5200, 7800, 0, 
0, 5200, 24700, 0, 0, 0, 32500, 6300, 11700, 58000, 10000, 0, 
0, 0, 7800, 10000, 0)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -21L))

Reading code from a screen shot ins difficult . Could you copy the code and paste in here between
```

```

I think that ` is ALTGR + * on a AZERTY keyboard.

This is how I might show the years where the value is greater than zero:

library(tidyverse)
tibble(
  Communes = c("ARRADON", "AURAY", "BADEN", "BELZ",
  "BRANDERION", "CAMORS", "ERDEVEN", "KERVIGNAC", "LOCQUELTAS",
  "MERLEVENEZ", "MEUCON", "NOSTANG", "PLESCOP", "PLOUHINEC", "PLUNERET",
  "SAINT-AVE", "SAINTE-HELENE", "SENE", "SULNIAC", "THEIX-NOYALO",
  "VANNES"), 
  `1998` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 
  `1999` = c(5200, 1500, 41900, 0, 0, 0, 31200, 0, 0, 0, 22100, 0, 15600, 47800, 14800, 0, 0, 0, 7800, 10400, 0), 
  `2000` = c(6500, 5200, 48300, 0, 0, 52000, 27300, 0, 0, 0, 31200, 0, 13000, 59300, 17800, 0, 0, 0, 9100, 10400, 0), 
  `2001` = c(6500, 5200, 33500, 0, 0, 3900, 0, 0, 0, 0, 26000, 14400, 14900, 51500, 19100, 0, 0, 0, 7800, 10400, 0), 
  `2002` = c(0, 5200, 7800, 0, 0, 5200, 24700, 0, 0, 0, 32500, 6300, 11700, 58000, 10000, 0, 0, 0, 7800, 10000, 0)
  ) %>% 
  pivot_longer(cols = -Communes, names_to = "year", values_to = "value") %>%
  arrange(desc(Communes)) %>%
  mutate(Communes = fct_inorder(Communes)) %>%
  ggplot(., aes(x = year, y = Communes)) +
  geom_path(aes(group = Communes, alpha = ifelse(value > 0, 1, 0)), color = "#dd0000", size = 2)+
  scale_alpha_identity()+
  theme_void()+
  theme(
    axis.text.y.left = element_text(hjust = 1),
    axis.text.x.bottom = element_text(hjust = .5)
  )

Thanks for your help.

Now, how could we based on the dataset make the figure I have indicated in my previous messages ?

Did you have an idea?

Oh I can see.

As matter of fact the code you're struggling to see in the screenshot is not even for the current exercise. I was working on another project.

Al I did is to follow what you said so as to past the result here.

I did not see this message from you. I think that is what I was looking for.
Thanks.