2

I’m trying to do a graphic with data that I send you a quick subset. The graphic I would like to have has on y axis the captors ("capteur") sorted by the number of data they have ("n") with a x axis showing atleast each month filled by values which are temperature values.

I’m struggling with the x axis which is the date. I don't know which format (date, POSIXct, factor ?) is the best to manage x axis. My goal is to have this format "day/month/year" (as exemple : "13/08/21") but as it should make the x axis unreadable, I would aslo be able to change it into month/year format ("08/21") (I should manage to do it myself just by deleting the first 3 characters ?)

example<-temp_plot%>%
  filter(capteur=="59-15-s." | capteur=="59-52-s." | capteur=="59-04-s." )
  select(1,5,8)
temp_plot<-example
dput(temp_plot)

> dput(example)
structure(list(capteur = structure(c(253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 253L, 253L, 253L, 253L, 253L, 253L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 
313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 
253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 
234L, 253L, 313L, 234L, 253L, 313L, 234L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 
253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 313L, 253L, 
313L, 253L, 313L, 253L, 313L), .Label = c("30-01-a.", "30-01-s.", 
"30-02-a.", "30-02-s.", "30-03-a.", "30-03-s.", "30-04-a.", "30-04-s.", 
"30-05-a.", "30-05-s.", "30-06-a.", "30-07-a.", "30-07-s.", "30-08-a.", 
"30-08-s.", "30-09-a.", "30-10-a.", "30-10-s.", "30-11-a.", "30-11-s.", 
"30-12-a.", "30-12-s.", "30-13-a.", "30-13-s.", "30-14-a.", "30-14-s.", 
"30-15-a.", "30-15-s.", "30-16-a.", "30-16-s.", "30-17-a.", "30-17-s.", 
"30-18-a.", "30-18-s.", "30-19-a.", "30-19-s.", "30-20-a.", "30-20-s.", 
"30-21-a.", "30-21-s.", "30-22-a.", "30-22-s.", "30-23-a.", "30-23-s.", 
"30-24-a.", "30-24-s.", "30-25-a.", "30-25-s.", "30-26-a.", "30-26-s.", 
"30-27-a.", "30-27-s.", "30-28-a.", "30-28-s.", "30-29-a.", "30-29-s.", 
"30-30-a.", "30-30-s.", "30-31-a.", "30-31-s.", "30-32-a.", "30-32-s.", 
"30-33-a.", "30-33-s.", "30-34-a.", "30-34-s.", "30-35-a.", "30-35-s.", 
"30-36-a.", "30-36-s.", "30-37-a.", "30-37-s.", "30-38-a.", "30-38-s.", 
"30-39-a.", "30-39-s.", "30-40-a.", "30-40-s.", "30-41-a.", "30-41-s.", 
"30-42-a.", "30-42-s.", "30-43-a.", "30-43-s.", "30-44-a.", "30-44-s.", 
"30-45-a.", "30-45-s.", "30-46-a.", "30-46-s.", "30-47-a.", "30-47-s.", 
"30-48-a.", "30-48-s.", "30-49-a.", "30-49-s.", "30-50-a.", "30-50-s.", 
"30-51-a.", "30-51-s.", "30-52-a.", "30-52-s.", "30-53-a.", "30-53-s.", 
"30-54-a.", "30-54-s.", "30-55-a.", "30-55-s.", "30-56-a.", "30-56-s.", 
"30-57-a.", "30-57-s.", "30-58-a.", "30-58-s.", "30-59-a.", "30-59-s.", 
"30-60-a.", "30-60-s.", "41-01-a.", "41-01-s.", "41-02-a.", "41-02-s.", 
"41-03-a.", "41-03-s.", "41-04-a.", "41-04-s.", "41-05-a.", "41-05-s.", 
"41-06-a.", "41-06-s.", "41-07-a.", "41-08-a.", "41-08-s.", "41-09-a.", 
"41-09-s.", "41-10-a.", "41-10-s.", "41-11-a.", "41-11-s.", "41-12-a.", 
"41-12-s.", "41-13-a.", "41-13-s.", "41-14-a.", "41-15-a.", "41-15-s.", 
"41-16-a.", "41-16-s.", "41-17-a.", "41-17-s.", "41-18-a.", "41-18-s.", 
"41-19-a.", "41-19-s.", "41-20-a.", "41-20-s.", "41-21-a.", "41-21-s.", 
"41-22-a.", "41-22-s.", "41-23-a.", "41-23-s.", "41-24-a.", "41-24-s.", 
"41-25-a.", "41-25-s.", "41-26-a.", "41-26-s.", "41-27-a.", "41-27-s.", 
"41-28-a.", "41-28-s.", "41-29-a.", "41-29-s.", "41-30-s.", "41-31-a.", 
"41-31-s.", "41-32-a.", "41-33-a.", "41-33-s.", "41-34-a.", "41-34-s.", 
"41-35-a.", "41-35-s.", "41-36-a.", "41-36-s.", "41-37-a.", "41-37-s.", 
"41-38-a.", "41-38-s.", "41-39-a.", "41-39-s.", "41-40-a.", "41-40-s.", 
"41-41-a.", "41-41-s.", "41-42-a.", "41-42-s.", "41-43-s.", "41-44-a.", 
"41-44-s.", "41-45-a.", "41-45-s.", "41-46-a.", "41-46-s.", "41-47-a.", 
"41-47-s.", "41-48-a.", "41-48-s.", "41-49-a.", "41-49-s.", "41-50-s.", 
"41-51-s.", "41-52-a.", "41-52-s.", "41-53-a.", "41-53-s.", "41-54-a.", 
"41-54-s.", "41-55-a.", "41-55-s.", "41-56-a.", "41-56-s.", "41-57-a.", 
"41-57-s.", "41-58-a.", "41-59-a.", "41-60-a.", "41-60-s.", "59-01-a.", 
"59-02-a.", "59-03-a.", "59-04-a.", "59-04-s.", "59-05-a.", "59-05-s.", 
"59-06-a.", "59-07-a.", "59-07-s.", "59-08-a.", "59-08-s.", "59-09-a.", 
"59-09-s.", "59-10-a.", "59-10-s.", "59-11-a.", "59-11-s.", "59-12-a.", 
"59-13-a.", "59-13-s.", "59-14-a.", "59-15-a.", "59-15-s.", "59-16-a.", 
"59-17-a.", "59-17-s.", "59-18-a.", "59-18-s.", "59-19-a.", "59-19-s.", 
"59-20-a.", "59-20-s.", "59-21-a.", "59-21-s.", "59-22-a.", "59-22-s.", 
"59-23-a.", "59-23-s.", "59-24-a.", "59-24-s.", "59-25-a.", "59-25-s.", 
"59-26-a.", "59-26-s.", "59-27-a.", "59-27-s.", "59-28-s.", "59-29-a.", 
"59-29-s.", "59-30-a.", "59-30-s.", "59-31-a.", "59-31-s.", "59-32-a.", 
"59-35-a.", "59-36-a.", "59-36-s.", "59-37-a.", "59-37-s.", "59-38-s.", 
"59-39-a.", "59-39-s.", "59-40-a.", "59-40-s.", "59-41-a.", "59-42-a.", 
"59-42-s.", "59-43-a.", "59-43-s.", "59-44-a.", "59-45-a.", "59-45-s.", 
"59-46-a.", "59-46-s.", "59-47-a.", "59-48-s.", "59-49-s.", "59-50-a.", 
"59-50-s.", "59-51-a.", "59-51-s.", "59-52-a.", "59-52-s.", "59-53-a.", 
"59-53-s.", "59-54-a.", "59-54-s.", "59-55-a.", "59-55-s.", "59-56-a.", 
"59-56-s.", "59-57-a.", "59-57-s.", "59-58-a.", "59-58-s.", "59-59-a.", 
"59-60-a.", "59-60-s."), class = "factor"), value = c(4.102, 
4.831, 3.049, 2.837, 3.578, 4.415, 2.837, 3.578, 2.73, 2.943, 
3.578, 3.998, 3.788, 4.623, 2.41, 2.088, 2.088, 1.221, 1.548, 
0.674, 4.207, 4.934, 6.674, 7.682, 4.519, 5.45, 3.155, 3.049, 
1.112, 0.674, 1.112, 0.674, 1.112, 0.453, 2.73, 3.683, 4.831, 
6.674, 6.775, 7.782, 6.775, 7.381, 5.86, 7.582, 3.893, 4.623, 
1.439, 0.893, 1.764, 2.517, 1.33, 3.893, 4.623, 5.347, 8.978, 
10.259, 8.481, 9.571, 6.064, 6.674, 4.519, 5.347, 5.86, 6.978, 
8.581, 11.139, 9.275, 10.553, 7.179, 8.082, 7.481, 10.161, 7.481, 
9.866, 2.837, 1.872, 1.764, 0.232, 1.221, -0.213, -0.662, -0.549, 
-0.662, -0.437, -1.341, -0.774, -1.114, -0.437, -0.213, 0.453, 
0.893, 2.943, 3.049, 9.472, 6.978, 11.722, 6.674, 8.978, 7.381, 
10.846, 8.879, 14.517, 8.581, 16.523, 9.669, 15.473, 11.334, 
18.045, 11.139, 16.141, 10.846, 16.332, 8.382, 11.916, 5.962, 
7.983, 8.182, 10.553, 9.373, 11.625, 11.431, 13.75, 12.207, 14.804, 
9.275, 7.882, 12.594, 7.28, 12.11, 7.582, 12.207, 8.282, 10.748, 
8.68, 13.173, 9.275, 14.613, 11.431, 16.332, 13.269, 12.401, 
10.944, 10.846, 11.041, 10.846, 10.063, 12.11, 13.365, 7.481, 
7.179, 8.68, 9.176, 8.282, 7.782, 14.517, 14.804, 15.951, 16.141, 
14.421, 11.139, 11.041, 8.879, 18.806, 18.806, 21.091, 22.046, 
11.139, 13.75, 13.461, 16.808, 10.357, 12.594, 15.951, 18.045, 
22.717, 24.545, 25.416, 27.665, 25.805, 27.37, 23.869, 25.416, 
18.045, 18.236, 17.57, 15.282, 18.901, 15.664, 7.079, 8.978, 
9.077, 14.038, 10.944, 17.094, 12.401, 14.23, 15.855, 20.71, 
9.176, 9.373, 10.455, 9.669, 11.819, 11.431, 13.365, 20.138, 
13.365, 14.421, 11.722, 17.95, 12.401, 20.329, 21.187, 20.234, 
24.641, 22.429, 24.158, 31.983, 23.004, 37.824, 25.61, 18.901, 
23.581, 33.535, 24.448, 36.62, 24.158, 36.511, 25.028, 34.479, 
20.519, 37.384, 23.196, 40.645, 23.196, 41.341, 11.334, 14.9, 
15.569, 15.855, 16.237, 16.427, 16.903, 17.189, 17.284, 17.379, 
31.472, 18.901, 17.379, 24.738, 18.711, 17.284, 18.045, 18.616, 
17.189, 17.855, 17.475, 16.903, 17.094, 17.284, 16.903, 16.808, 
17.57, 16.808, 16.808, 19.092, 17.284, 18.236, 18.426, 17.379, 
18.331, 17.189, 16.903, 16.903, 16.237, 16.523, 16.237, 15.76, 
16.332, 15.76, 16.523, 16.332, 15.951, 15.569, 16.141, 15.76, 
15.569, 15.951, 15.378, 15.187, 15.76, 15.282, 14.709, 15.282, 
14.517, 14.804, 15.282, 14.804, 14.613, 15.091, 14.421, 14.517, 
14.9, 14.23, 14.325, 14.804, 14.038, 15.569, 15.282, 14.804, 
16.046, 15.569, 15.473, 15.187, 15.187, 14.996, 14.134, 14.709, 
13.654, 14.134, 14.613, 13.558, 14.996, 14.804, 14.134, 16.237, 
19.472, 15.473, 15.76, 18.14, 15.473, 15.473, 18.521, 14.9, 14.996, 
17.379, 14.421, 15.282, 18.806, 14.517, 16.427, 21.569, 15.378, 
17.57, 23.773, 16.332, 17.665, 23.581, 16.523, 16.237, 18.14, 
15.855, 15.664, 20.901, 14.9, 16.332, 22.142, 15.664, 16.808, 
22.333, 16.046, 15.664, 20.234, 14.613, 15.187, 18.901, 14.23, 
15.282, 18.045, 14.421, 13.75, 14.9, 13.942, 12.11, 11.139, 12.787, 
11.139, 10.846, 11.722, 12.69, 14.23, 12.497, 12.497, 12.594, 
12.401, 13.654, 14.804, 13.173, 14.23, 15.664, 13.75, 13.846, 
13.365, 13.654, 12.98, 13.076, 12.787, 12.69, 12.304, 12.69, 
11.916, 11.819, 12.207, 12.11, 13.076, 12.207, 12.11, 13.365, 
12.304, 11.916, 12.787, 12.207, 13.269, 14.804, 12.98, 12.98, 
13.654, 12.883, 11.431, 11.528, 12.013, 11.139, 10.651, 11.139, 
10.944, 11.236, 11.139, 10.553, 8.978, 10.846, 10.259, 10.259, 
10.357, 10.063, 9.768, 10.357, 10.063, 10.455, 10.259, 10.063, 
9.965, 10.161, 10.357, 11.041, 10.259, 10.259, 11.236, 10.161, 
11.431, 12.401, 11.139, 12.594, 15.378, 12.207, 12.98, 14.996, 
12.497, 12.787, 14.23, 12.401, 12.497, 13.558, 12.304, 12.207, 
11.722, 12.304, 10.944, 10.944, 11.528, 10.846, 11.041, 10.944, 
10.846, 11.431, 11.139, 11.334, 11.916, 11.236, 11.916, 13.173, 
11.819, 12.11, 13.173, 12.11, 13.654, 15.187, 12.98, 13.942, 
16.237, 13.654, 11.334, 10.748, 12.304, 9.768, 9.373, 10.553, 
9.176, 8.581, 9.077, 8.879, 8.879, 8.779, 9.965, 11.334, 9.472, 
10.846, 12.11, 10.161, 11.236, 13.076, 10.455, 11.139, 11.722, 
10.553, 11.236, 11.431, 10.846, 10.944, 10.944, 10.748, 10.944, 
11.041, 10.553, 11.139, 11.625, 10.944, 11.334, 11.625, 11.139, 
10.455, 10.553, 10.553, 10.553, 10.846, 10.651, 10.651, 10.748, 
10.651, 10.357, 9.965, 10.553, 9.275, 7.882, 9.866, 8.779, 8.282, 
8.978, 9.275, 8.978, 9.373, 9.571, 9.768, 9.571, 9.472, 8.879, 
9.571, 8.68, 8.182, 8.779, 8.481, 7.682, 8.481, 7.983, 6.573, 
7.782, 7.983, 7.079, 7.582, 7.28, 4.623, 7.28, 6.674, 5.552, 
6.775, 7.381, 7.079, 7.28, 7.582, 7.079, 7.582, 7.381, 6.268, 
7.481, 7.381, 5.757, 7.179, 6.471, 4.727, 6.573, 6.064, 3.998, 
6.268, 5.655, 3.683, 5.45, 5.552, 3.788, 5.45, 5.347, 3.788, 
5.347, 5.552, 4.102, 5.552, 6.166, 6.166, 5.962, 7.179, 6.877, 
6.573, 6.775, 7.882, 9.373, 8.68, 10.357, 7.983, 9.669, 7.983, 
9.176, 7.481, 8.382, 7.983, 9.472, 8.282, 9.275, 10.259, 11.819, 
11.528, 13.365, 11.528, 11.722, 8.182, 6.471, 6.064, 5.552, 5.45, 
5.45, 5.552, 5.552, 5.141, 5.244, 4.831, 5.037, 5.037, 5.86, 
4.207, 4.727), date = structure(c(1609455600, 1609455600, 1609542000, 
1609542000, 1609628400, 1609628400, 1609714800, 1609714800, 1609801200, 
1609801200, 1609887600, 1609887600, 1609974000, 1609974000, 1610060400, 
1610060400, 1610146800, 1610146800, 1610233200, 1610233200, 1610319600, 
1610319600, 1610406000, 1610406000, 1610492400, 1610492400, 1610578800, 
1610578800, 1610665200, 1610665200, 1610751600, 1610751600, 1610838000, 
1610838000, 1610924400, 1610924400, 1611010800, 1611010800, 1611097200, 
1611097200, 1611183600, 1611183600, 1611270000, 1611270000, 1611356400, 
1611356400, 1611442800, 1611442800, 1611529200, 1611529200, 1611615600, 
1611615600, 1611702000, 1611702000, 1611788400, 1611788400, 1611874800, 
1611874800, 1611961200, 1611961200, 1612047600, 1612047600, 1612134000, 
1612134000, 1612220400, 1612220400, 1612306800, 1612306800, 1612393200, 
1612393200, 1612479600, 1612479600, 1612566000, 1612566000, 1612652400, 
1612652400, 1612738800, 1612738800, 1612825200, 1612825200, 1612911600, 
1612911600, 1612998000, 1612998000, 1613084400, 1613084400, 1613170800, 
1613170800, 1613257200, 1613257200, 1613343600, 1613343600, 1613430000, 
1613430000, 1613516400, 1613516400, 1613602800, 1613602800, 1613689200, 
1613689200, 1613775600, 1613775600, 1613862000, 1613862000, 1613948400, 
1613948400, 1614034800, 1614034800, 1614121200, 1614121200, 1614207600, 
1614207600, 1614294000, 1614294000, 1614380400, 1614380400, 1614466800, 
1614466800, 1614553200, 1614553200, 1614639600, 1614639600, 1614726000, 
1614726000, 1614812400, 1614812400, 1614898800, 1614898800, 1614985200, 
1614985200, 1615071600, 1615071600, 1615158000, 1615158000, 1615244400, 
1615244400, 1615330800, 1615330800, 1615417200, 1615417200, 1615503600, 
1615503600, 1615590000, 1615590000, 1615676400, 1615676400, 1615762800, 
1615762800, 1615849200, 1615849200, 1615935600, 1615935600, 1616022000, 
1616022000, 1616108400, 1616108400, 1616194800, 1616194800, 1616281200, 
1616281200, 1616367600, 1616367600, 1616454000, 1616454000, 1616540400, 
1616540400, 1616626800, 1616626800, 1616713200, 1616713200, 1616799600, 
1616799600, 1616886000, 1616886000, 1616968800, 1616968800, 1617055200, 
1617055200, 1617141600, 1617141600, 1617228000, 1617228000, 1617314400, 
1617314400, 1617400800, 1617400800, 1617487200, 1617487200, 1617573600, 
1617573600, 1617660000, 1617660000, 1617746400, 1617746400, 1617832800, 
1617832800, 1617919200, 1617919200, 1618005600, 1618005600, 1618092000, 
1618092000, 1618178400, 1618178400, 1618264800, 1618264800, 1618351200, 
1618351200, 1618437600, 1618437600, 1618524000, 1618524000, 1618610400, 
1618610400, 1618696800, 1618696800, 1618783200, 1618783200, 1618869600, 
1618869600, 1618956000, 1618956000, 1619042400, 1619042400, 1619128800, 
1619128800, 1619215200, 1619215200, 1619301600, 1619301600, 1619388000, 
1619388000, 1619474400, 1619474400, 1619560800, 1619560800, 1619647200, 
1619647200, 1596664800, 1596751200, 1596837600, 1596924000, 1597010400, 
1597096800, 1597183200, 1597269600, 1597269600, 1597356000, 1597356000, 
1597356000, 1597442400, 1597442400, 1597442400, 1597528800, 1597528800, 
1597528800, 1597615200, 1597615200, 1597615200, 1597701600, 1597701600, 
1597701600, 1597788000, 1597788000, 1597788000, 1597874400, 1597874400, 
1597874400, 1597960800, 1597960800, 1597960800, 1598047200, 1598047200, 
1598047200, 1598133600, 1598133600, 1598133600, 1598220000, 1598220000, 
1598220000, 1598306400, 1598306400, 1598306400, 1598392800, 1598392800, 
1598392800, 1598479200, 1598479200, 1598479200, 1598565600, 1598565600, 
1598565600, 1598652000, 1598652000, 1598652000, 1598738400, 1598738400, 
1598738400, 1598824800, 1598824800, 1598824800, 1598911200, 1598911200, 
1598911200, 1598997600, 1598997600, 1598997600, 1599084000, 1599084000, 
1599084000, 1599170400, 1599170400, 1599170400, 1599256800, 1599256800, 
1599256800, 1599343200, 1599343200, 1599343200, 1599429600, 1599429600, 
1599429600, 1599516000, 1599516000, 1599516000, 1599602400, 1599602400, 
1599602400, 1599688800, 1599688800, 1599688800, 1599775200, 1599775200, 
1599775200, 1599861600, 1599861600, 1599861600, 1599948000, 1599948000, 
1599948000, 1600034400, 1600034400, 1600034400, 1600120800, 1600120800, 
1600120800, 1600207200, 1600207200, 1600207200, 1600293600, 1600293600, 
1600293600, 1600380000, 1600380000, 1600380000, 1600466400, 1600466400, 
1600466400, 1600552800, 1600552800, 1600552800, 1600639200, 1600639200, 
1600639200, 1600725600, 1600725600, 1600725600, 1600812000, 1600812000, 
1600812000, 1600898400, 1600898400, 1600898400, 1600984800, 1600984800, 
1600984800, 1601071200, 1601071200, 1601071200, 1601157600, 1601157600, 
1601157600, 1601244000, 1601244000, 1601244000, 1601330400, 1601330400, 
1601330400, 1601416800, 1601416800, 1601416800, 1601503200, 1601503200, 
1601503200, 1601589600, 1601589600, 1601589600, 1601676000, 1601676000, 
1601676000, 1601762400, 1601762400, 1601762400, 1601848800, 1601848800, 
1601848800, 1601935200, 1601935200, 1601935200, 1602021600, 1602021600, 
1602021600, 1602108000, 1602108000, 1602108000, 1602194400, 1602194400, 
1602194400, 1602280800, 1602280800, 1602280800, 1602367200, 1602367200, 
1602367200, 1602453600, 1602453600, 1602453600, 1602540000, 1602540000, 
1602540000, 1602626400, 1602626400, 1602626400, 1602712800, 1602712800, 
1602712800, 1602799200, 1602799200, 1602799200, 1602885600, 1602885600, 
1602885600, 1602972000, 1602972000, 1602972000, 1603058400, 1603058400, 
1603058400, 1603144800, 1603144800, 1603144800, 1603231200, 1603231200, 
1603231200, 1603317600, 1603317600, 1603317600, 1603404000, 1603404000, 
1603404000, 1603490400, 1603490400, 1603490400, 1603576800, 1603576800, 
1603576800, 1603666800, 1603666800, 1603666800, 1603753200, 1603753200, 
1603753200, 1603839600, 1603839600, 1603839600, 1603926000, 1603926000, 
1603926000, 1604012400, 1604012400, 1604012400, 1604098800, 1604098800, 
1604098800, 1604185200, 1604185200, 1604185200, 1604271600, 1604271600, 
1604271600, 1604358000, 1604358000, 1604358000, 1604444400, 1604444400, 
1604444400, 1604530800, 1604530800, 1604530800, 1604617200, 1604617200, 
1604617200, 1604703600, 1604703600, 1604703600, 1604790000, 1604790000, 
1604790000, 1604876400, 1604876400, 1604876400, 1604962800, 1604962800, 
1604962800, 1605049200, 1605049200, 1605049200, 1605135600, 1605135600, 
1605135600, 1605222000, 1605222000, 1605222000, 1605308400, 1605308400, 
1605308400, 1605394800, 1605394800, 1605394800, 1605481200, 1605481200, 
1605481200, 1605567600, 1605567600, 1605567600, 1605654000, 1605654000, 
1605654000, 1605740400, 1605740400, 1605740400, 1605826800, 1605826800, 
1605826800, 1605913200, 1605913200, 1605913200, 1605999600, 1605999600, 
1605999600, 1606086000, 1606086000, 1606086000, 1606172400, 1606172400, 
1606172400, 1606258800, 1606258800, 1606258800, 1606345200, 1606345200, 
1606345200, 1606431600, 1606431600, 1606431600, 1606518000, 1606518000, 
1606518000, 1606604400, 1606604400, 1606604400, 1606690800, 1606690800, 
1606690800, 1606777200, 1606777200, 1606777200, 1606863600, 1606863600, 
1606863600, 1606950000, 1606950000, 1606950000, 1607036400, 1607036400, 
1607036400, 1607122800, 1607122800, 1607122800, 1607209200, 1607209200, 
1607209200, 1607295600, 1607295600, 1607295600, 1607382000, 1607382000, 
1607382000, 1607468400, 1607468400, 1607468400, 1607554800, 1607554800, 
1607554800, 1607641200, 1607641200, 1607641200, 1607727600, 1607727600, 
1607814000, 1607814000, 1607900400, 1607900400, 1607986800, 1607986800, 
1608073200, 1608073200, 1608159600, 1608159600, 1608246000, 1608246000, 
1608332400, 1608332400, 1608418800, 1608418800, 1608505200, 1608505200, 
1608591600, 1608591600, 1608678000, 1608678000, 1608764400, 1608764400, 
1608850800, 1608850800, 1608937200, 1608937200, 1609023600, 1609023600, 
1609110000, 1609110000, 1609196400, 1609196400, 1609282800, 1609282800, 
1609369200, 1609369200), tzone = "", class = c("POSIXct", "POSIXt"
))), row.names = c(NA, -647L), class = "data.frame")

#creating a variable to sort my captor ("capteur") from the one with the most data to the one with the less
temp_plot<-temp_plot%>%
  group_by(capteur)%>%
  mutate(n=n())

# Order my data to the way I want 
temp_plot$capteur <- factor(temp_plot$capteur, levels=rev(unique(temp_plot$capteur)), ordered=TRUE)

#Changing into the date format I want 
temp_plot$date<-strftime(temp_plot$date,"%d/%m/%Y")
class(temp_plot$date)

temp_plot%>%
  ggplot(aes(x=date,y=reorder(capteur,n),fill=value))+
  geom_tile() + 
  scale_fill_distiller(palette="Spectral")+
  theme(axis.text.x = element_text(angle=45, hjust = 1))+
  theme_classic()

Do you think you can help me on this one ? Im not really use with graphics and date format.

Thank you

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

2

Salut Germain, @RichardTelford gave you basically the answer already.

There are different philosophies, but I recommend to stick to the object-type and only coerce to other types as the last resort. Thus, as you work with dates, stick to dates or datetimes. The benefit of sticking to the correct types is that you can build on things like natural ordering, formatting, etc.
Again - only revert to other types, if you need to "hack" your desired result.

If we "rewind" to the following step:

temp_plot<-temp_plot%>%
  group_by(capteur)%>%
  mutate(n=n())

You are creating a long dataframe of the following form:

temp_plot
# A tibble: 647 x 4
# Groups:   capteur [3]
   capteur  value date                    n
   <fct>    <dbl> <dttm>              <int>
 1 59-15-s.  4.10 2021-01-01 00:00:00   267
 2 59-52-s.  4.83 2021-01-01 00:00:00   260
 3 59-15-s.  3.05 2021-01-02 00:00:00   267
 4 59-52-s.  2.84 2021-01-02 00:00:00   260
 5 59-15-s.  3.58 2021-01-03 00:00:00   267
 6 59-52-s.  4.42 2021-01-03 00:00:00   260
 7 59-15-s.  2.84 2021-01-04 00:00:00   267
 8 59-52-s.  3.58 2021-01-04 00:00:00   260
 9 59-15-s.  2.73 2021-01-05 00:00:00   267
10 59-52-s.  2.94 2021-01-05 00:00:00   260

From this you can derive that your "date" column is actually a datetime type. {ggplot2} offers many type oriented scales. Here we have to use the scale_x_datetime() call.

Note: I skip the theme() part, to focus on the scale bit. You can add that later again.

temp_plot %>% 
    ggplot(aes(x=date,y=reorder(capteur,n),fill=value))+
    geom_tile() + 
    scale_fill_distiller(palette="Spectral") +
#---------- define the type-correct scale 
    scale_x_datetime()

This yields "out of the box":

scale_x_datetime()

In the next step you can now define the "breaks" and "labels". Note: the label work is easy because we have "date/datetimes", if you would have coerced the type, this would require providing a vector of your desired values.
Here we can now make use of the build-in label formats. Read up on the different options.

temp_plot %>% 
    ggplot(aes(x=date,y=reorder(capteur,n),fill=value))+
    geom_tile() + 
    scale_fill_distiller(palette="Spectral") +
    scale_x_datetime(
          date_breaks = "2 months"  # the "major" breaks of your x-axis
        , date_labels = "%b %y"     # formatting, here shortened Month and Year
    )

specifying breaks for scale_x_datetime

As an exercise, you may want to look into changing your date column into a date-object and work with scale_x_date(). The principles will be the same. However, I recommend to stay away from making it a factor or character and try to emulate the same output. Good luck.

Again, kudos to Richard Telford who pointed out the answer already! This shows you the application of it.

Ray
  • 2,008
  • 14
  • 21