I have a dataset in which I want to plot the measurements of a substance at different locations over time over time. this works with a simple line plot. However, I have some moments in my data when no measurements were executed these moments I want the lines to break. I have added some dates with NA values. However it does not present break.
The code goes like this:
chloride <- subset(df, Parameter == "chloride - nf - mg/l")
ggplot(data = chloride2, aes(x = Datum, y = as.numeric(as.factor(Waarden)))) +
  geom_line(aes(color = Locatie), lwd = 1) +
  labs(x = "Datum", y = "Chloride (mg/l)") +
  scale_color_manual(values = c("navy", "darkslategray4", "orange", "yellowgreen", "cornflowerblue", "firebrick")) +
  theme_bw() +
  theme(text = element_text(size = 16), legend.position = "top") +
  scale_y_continuous(limits = c(0, 220)) +
  geom_hline(yintercept = 200, linetype = "dashed") +
  scale_x_date(date_breaks = ("1 year"), labels = date_format("%m/%Y"))
I have tried it with another substance here only one location was included tried this code
extinction <- subset(df, Parameter == "Extinctie")
every.year <- data.frame(Datum = seq(min(extinction$Datum), max(extinction$Datum), by = "1 year"))
extinction2 <- merge(extinction, every.year, all = TRUE)
ggplot(data = extinction2, aes(x = Datum, y = Waarden)) +
  geom_line(color = "steelblue", lwd = 1) +
  labs(y = "Extinctie-waarden", x = "Datum") +
  theme_bw() +
  theme(text = element_text(size = 16)) +
  scale_y_continuous(limit = c(0, 15)) +
  scale_x_date(date_breaks = ("3 month"), labels = date_format("%m/%Y"))
This worked.
it seems like it does not present a break because of the different locations
    Datum            Parameter Waarden                                      Locatie
1   2016-02-08 chloride - nf - mg/l    89.0                    Waterskivijver Wollebrand
2   2016-04-26 chloride - nf - mg/l    93.0                    Waterskivijver Wollebrand
3   2016-05-24 chloride - nf - mg/l    81.0                    Waterskivijver Wollebrand
4   2016-06-16 chloride - nf - mg/l    74.0                    Waterskivijver Wollebrand
5   2016-06-16 chloride - nf - mg/l    62.0                   Wollebrand_Inlaat zwemplas
6   2016-06-16 chloride - nf - mg/l    70.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
7   2016-06-16 chloride - nf - mg/l    63.0                veilingroute_bovenstroom stuw
8   2016-06-16 chloride - nf - mg/l    59.0                          Strijp_inlaat FLORA
9   2016-06-21 chloride - nf - mg/l    51.0                    Waterskivijver Wollebrand
10  2016-06-28 chloride - nf - mg/l    45.0                    Waterskivijver Wollebrand
11  2016-06-28 chloride - nf - mg/l    33.0                   Wollebrand_Inlaat zwemplas
12  2016-06-28 chloride - nf - mg/l    36.0                          Strijp_inlaat FLORA
13  2016-06-28 chloride - nf - mg/l    47.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
14  2016-06-28 chloride - nf - mg/l    82.0                veilingroute_bovenstroom stuw
15  2016-07-08 chloride - nf - mg/l    46.0                   Wollebrand_Inlaat zwemplas
16  2016-07-08 chloride - nf - mg/l    54.0                    Waterskivijver Wollebrand
17  2016-07-08 chloride - nf - mg/l    46.0                veilingroute_bovenstroom stuw
18  2016-07-08 chloride - nf - mg/l    42.0                          Strijp_inlaat FLORA
19  2016-07-11 chloride - nf - mg/l    63.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
20  2016-07-19 chloride - nf - mg/l    68.0                    Waterskivijver Wollebrand
21  2016-07-19 chloride - nf - mg/l    65.0                   Wollebrand_Inlaat zwemplas
22  2016-07-19 chloride - nf - mg/l    72.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
23  2016-07-19 chloride - nf - mg/l    53.0                veilingroute_bovenstroom stuw
24  2016-07-19 chloride - nf - mg/l    45.0                          Strijp_inlaat FLORA
25  2016-08-01 chloride - nf - mg/l    54.0                   Wollebrand_Inlaat zwemplas
26  2016-08-01 chloride - nf - mg/l    65.0                    Waterskivijver Wollebrand
27  2016-08-01 chloride - nf - mg/l    62.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
28  2016-08-01 chloride - nf - mg/l    45.0                veilingroute_bovenstroom stuw
29  2016-08-01 chloride - nf - mg/l    48.0                          Strijp_inlaat FLORA
30  2016-08-16 chloride - nf - mg/l    61.0                    Waterskivijver Wollebrand
31  2016-08-16 chloride - nf - mg/l    61.0                    Waterskivijver Wollebrand
32  2016-08-16 chloride - nf - mg/l    58.0                   Wollebrand_Inlaat zwemplas
33  2016-08-16 chloride - nf - mg/l    62.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
34  2016-08-16 chloride - nf - mg/l    57.0                veilingroute_bovenstroom stuw
35  2016-08-16 chloride - nf - mg/l    56.0                          Strijp_inlaat FLORA
36  2016-08-30 chloride - nf - mg/l    48.0                    Waterskivijver Wollebrand
37  2016-09-02 chloride - nf - mg/l    58.0                          Strijp_inlaat FLORA
38  2016-09-02 chloride - nf - mg/l    51.0                    Waterskivijver Wollebrand
39  2016-09-02 chloride - nf - mg/l    54.0                   Wollebrand_Inlaat zwemplas
40  2016-09-02 chloride - nf - mg/l    56.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
41  2016-09-02 chloride - nf - mg/l    60.0                veilingroute_bovenstroom stuw
42  2016-09-13 chloride - nf - mg/l    64.0                    Waterskivijver Wollebrand
43  2016-09-15 chloride - nf - mg/l    68.0                    Waterskivijver Wollebrand
44  2016-09-15 chloride - nf - mg/l    76.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
45  2016-09-15 chloride - nf - mg/l    72.0                   Wollebrand_Inlaat zwemplas
46  2016-09-15 chloride - nf - mg/l    75.0                veilingroute_bovenstroom stuw
47  2016-09-15 chloride - nf - mg/l    72.0                          Strijp_inlaat FLORA
48  2016-09-30 chloride - nf - mg/l    75.0                    Waterskivijver Wollebrand
49  2016-09-30 chloride - nf - mg/l    74.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
50  2016-09-30 chloride - nf - mg/l    63.0                   Wollebrand_Inlaat zwemplas
51  2016-09-30 chloride - nf - mg/l    68.0                veilingroute_bovenstroom stuw
52  2016-09-30 chloride - nf - mg/l    71.0                          Strijp_inlaat FLORA
53  2016-10-10 chloride - nf - mg/l    75.0                    Waterskivijver Wollebrand
54  2016-10-10 chloride - nf - mg/l    74.0                   Wollebrand_Inlaat zwemplas
55  2016-10-10 chloride - nf - mg/l    76.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
56  2016-10-10 chloride - nf - mg/l    76.0                veilingroute_bovenstroom stuw
57  2016-10-10 chloride - nf - mg/l    74.0                          Strijp_inlaat FLORA
58  2016-10-25 chloride - nf - mg/l    70.0                    Waterskivijver Wollebrand
59  2016-10-25 chloride - nf - mg/l    66.0                   Wollebrand_Inlaat zwemplas
60  2016-10-25 chloride - nf - mg/l    64.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
61  2016-10-25 chloride - nf - mg/l    65.0                veilingroute_bovenstroom stuw
62  2016-10-25 chloride - nf - mg/l    67.0                          Strijp_inlaat FLORA
63  2016-11-07 chloride - nf - mg/l    60.0                    Waterskivijver Wollebrand
64  2016-11-14 chloride - nf - mg/l    62.0                    Waterskivijver Wollebrand
65  2016-11-14 chloride - nf - mg/l    52.0                   Wollebrand_Inlaat zwemplas
66  2016-11-14 chloride - nf - mg/l    60.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
67  2016-11-14 chloride - nf - mg/l    63.0                veilingroute_bovenstroom stuw
68  2016-11-14 chloride - nf - mg/l    52.0                          Strijp_inlaat FLORA
69  2016-12-20 chloride - nf - mg/l    76.0                    Waterskivijver Wollebrand
70  2016-12-20 chloride - nf - mg/l    84.0                   Wollebrand_Inlaat zwemplas
71  2016-12-20 chloride - nf - mg/l    83.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
72  2016-12-20 chloride - nf - mg/l    93.0                veilingroute_bovenstroom stuw
73  2016-12-20 chloride - nf - mg/l    97.0                          Strijp_inlaat FLORA
74  2017-01-13 chloride - nf - mg/l   103.0                    Waterskivijver Wollebrand
75  2017-01-13 chloride - nf - mg/l    49.2                   Wollebrand_Inlaat zwemplas
76  2017-01-13 chloride - nf - mg/l    68.2 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
77  2017-01-13 chloride - nf - mg/l    60.8                veilingroute_bovenstroom stuw
78  2017-01-13 chloride - nf - mg/l    61.7                          Strijp_inlaat FLORA
79  2017-02-08                 <NA>      NA                                         <NA>
80  2017-02-13 chloride - nf - mg/l    73.4                          Strijp_inlaat FLORA
81  2017-02-13 chloride - nf - mg/l    99.5                    Waterskivijver Wollebrand
82  2017-02-13 chloride - nf - mg/l   133.0                   Wollebrand_Inlaat zwemplas
83  2017-02-13 chloride - nf - mg/l   110.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
84  2017-02-13 chloride - nf - mg/l    99.1                veilingroute_bovenstroom stuw
85  2017-03-07 chloride - nf - mg/l    95.7                    Waterskivijver Wollebrand
86  2017-03-09 chloride - nf - mg/l    55.3                   Wollebrand_Inlaat zwemplas
87  2017-03-09 chloride - nf - mg/l    74.5 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
88  2017-03-09 chloride - nf - mg/l    71.7                veilingroute_bovenstroom stuw
89  2017-03-09 chloride - nf - mg/l    64.3                          Strijp_inlaat FLORA
90  2017-04-04 chloride - nf - mg/l    99.1                   Wollebrand_Inlaat zwemplas
91  2017-04-04 chloride - nf - mg/l   111.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
92  2017-04-04 chloride - nf - mg/l   101.0                veilingroute_bovenstroom stuw
93  2017-04-04 chloride - nf - mg/l    91.2                          Strijp_inlaat FLORA
94  2017-04-25 chloride - nf - mg/l   107.0                    Waterskivijver Wollebrand
95  2017-05-02 chloride - nf - mg/l   111.0                   Wollebrand_Inlaat zwemplas
96  2017-05-02 chloride - nf - mg/l   123.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
97  2017-05-02 chloride - nf - mg/l   143.0                veilingroute_bovenstroom stuw
98  2017-05-02 chloride - nf - mg/l   132.0                          Strijp_inlaat FLORA
99  2017-05-02 chloride - nf - mg/l   113.0       Waterskivijver Wollebrand steiger-vlot
100 2017-05-23 chloride - nf - mg/l   147.0                    Waterskivijver Wollebrand
101 2017-06-06 chloride - nf - mg/l   100.0                   Wollebrand_Inlaat zwemplas
102 2017-06-06 chloride - nf - mg/l   147.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
103 2017-06-06 chloride - nf - mg/l    99.0                veilingroute_bovenstroom stuw
104 2017-06-06 chloride - nf - mg/l    88.2                          Strijp_inlaat FLORA
105 2017-06-06 chloride - nf - mg/l   144.0       Waterskivijver Wollebrand steiger-vlot
106 2017-06-20 chloride - nf - mg/l   127.0                    Waterskivijver Wollebrand
107 2017-07-05 chloride - nf - mg/l   105.0                   Wollebrand_Inlaat zwemplas
108 2017-07-05 chloride - nf - mg/l   103.0 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
109 2017-07-05 chloride - nf - mg/l   106.0                veilingroute_bovenstroom stuw
110 2017-07-05 chloride - nf - mg/l    84.3                          Strijp_inlaat FLORA
111 2017-07-05 chloride - nf - mg/l   118.0       Waterskivijver Wollebrand steiger-vlot
112 2017-07-18 chloride - nf - mg/l    92.9                    Waterskivijver Wollebrand
113 2017-08-03 chloride - nf - mg/l    72.1                   Wollebrand_Inlaat zwemplas
114 2017-08-03 chloride - nf - mg/l    65.4 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
115 2017-08-03 chloride - nf - mg/l    63.3                veilingroute_bovenstroom stuw
116 2017-08-03 chloride - nf - mg/l    72.7                          Strijp_inlaat FLORA
117 2017-08-03 chloride - nf - mg/l    84.2       Waterskivijver Wollebrand steiger-vlot
118 2017-08-15 chloride - nf - mg/l    85.4                    Waterskivijver Wollebrand
119 2017-09-05 chloride - nf - mg/l    70.9                veilingroute_bovenstroom stuw
120 2017-09-05 chloride - nf - mg/l    68.6       Waterskivijver Wollebrand steiger-vlot
121 2017-09-05 chloride - nf - mg/l    63.1                   Wollebrand_Inlaat zwemplas
122 2017-09-05 chloride - nf - mg/l    66.8 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
123 2017-09-05 chloride - nf - mg/l    55.5                          Strijp_inlaat FLORA
124 2017-09-12 chloride - nf - mg/l    52.5                    Waterskivijver Wollebrand
125 2017-10-05 chloride - nf - mg/l    39.2                   Wollebrand_Inlaat zwemplas
126 2017-10-05 chloride - nf - mg/l    33.3                veilingroute_bovenstroom stuw
127 2017-10-05 chloride - nf - mg/l    37.5                          Strijp_inlaat FLORA
128 2017-10-05 chloride - nf - mg/l    66.5       Waterskivijver Wollebrand steiger-vlot
129 2017-10-31 chloride - nf - mg/l    81.3 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
130 2017-11-09 chloride - nf - mg/l    70.5                   Wollebrand_Inlaat zwemplas
131 2017-11-09 chloride - nf - mg/l    82.6 hoofdwatergang_Lange Broekweg nr 78 (?)_tuin
132 2017-11-09 chloride - nf - mg/l    72.0                veilingroute_bovenstroom stuw
133 2017-11-09 chloride - nf - mg/l    66.3                          Strijp_inlaat FLORA
134 2017-11-09 chloride - nf - mg/l    85.8       Waterskivijver Wollebrand steiger-vlot
135 2017-11-16 chloride - nf - mg/l    85.9       Waterskivijver Wollebrand steiger-vlot
136 2017-12-06 chloride - nf - mg/l    75.9                   Wollebrand_Inlaat zwemplas
137 2017-12-06 chloride - nf - mg/l    68.7                veilingroute_bovenstroom stuw
138 2017-12-06 chloride - nf - mg/l    58.5                          Strijp_inlaat FLORA
139 2017-12-06 chloride - nf - mg/l    86.9       Waterskivijver Wollebrand steiger-vlot
140 2018-02-08                 <NA>      NA                                         <NA>
141 2019-01-08 chloride - nf - mg/l   131.0                    Waterskivijver Wollebrand
142 2019-02-08                 <NA>      NA                                         <NA>
143 2019-02-18 chloride - nf - mg/l   141.0                    Waterskivijver Wollebrand
144 2019-02-26 chloride - nf - mg/l   142.0                    Waterskivijver Wollebrand
145 2019-04-26 chloride - nf - mg/l    86.6                   Wollebrand_Inlaat zwemplas
146 2019-04-30 chloride - nf - mg/l   115.0                    Waterskivijver Wollebrand
147 2019-05-14 chloride - nf - mg/l   121.0                    Waterskivijver Wollebrand
148 2019-05-23 chloride - nf - mg/l   115.0                   Wollebrand_Inlaat zwemplas
149 2019-05-28 chloride - nf - mg/l   117.0                    Waterskivijver Wollebrand
150 2019-05-28 chloride - nf - mg/l   113.0                    Waterskivijver Wollebrand
151 2019-06-12 chloride - nf - mg/l    96.7                    Waterskivijver Wollebrand
152 2019-06-25 chloride - nf - mg/l    91.3                    Waterskivijver Wollebrand
153 2019-06-25 chloride - nf - mg/l    88.2                   Wollebrand_Inlaat zwemplas
154 2019-07-09 chloride - nf - mg/l   101.0                    Waterskivijver Wollebrand
155 2019-07-11 chloride - nf - mg/l    89.3                   Wollebrand_Inlaat zwemplas
156 2019-07-23 chloride - nf - mg/l    92.1                    Waterskivijver Wollebrand
157 2019-08-06 chloride - nf - mg/l    85.6                    Waterskivijver Wollebrand
158 2019-08-20 chloride - nf - mg/l    75.2                    Waterskivijver Wollebrand
159 2019-08-20 chloride - nf - mg/l    76.4                    Waterskivijver Wollebrand
160 2019-08-26 chloride - nf - mg/l    91.6                   Wollebrand_Inlaat zwemplas
161 2019-09-03 chloride - nf - mg/l    89.9                    Waterskivijver Wollebrand
162 2019-09-17 chloride - nf - mg/l    84.9                    Waterskivijver Wollebrand
163 2019-09-24 chloride - nf - mg/l    92.7                    Waterskivijver Wollebrand
164 2019-09-26 chloride - nf - mg/l    68.9                   Wollebrand_Inlaat zwemplas
165 2019-10-30 chloride - nf - mg/l   109.0                   Wollebrand_Inlaat zwemplas
166 2019-11-07 chloride - nf - mg/l    94.5                    Waterskivijver Wollebrand
167 2019-11-29 chloride - nf - mg/l    82.9                   Wollebrand_Inlaat zwemplas
168 2019-12-24 chloride - nf - mg/l   100.0                   Wollebrand_Inlaat zwemplas
> 
  [1]: https://i.stack.imgur.com/mjB6G.png
 
    


