0

I have daily time-series data (2015, 2017, 2018) that I want to plot. The data is not complete each year as well, for example, there are missing values in February 2018. When I plot it, there is a straight line connecting every missing value.

Here is the example of data:

structure(list(station = c("NYA", "NYA", "NYA", "NYA", "NYA", 
"NYA", "NYA", "NYA", "NYA", "NYA", "NYA"), date = structure(c(1505952000, 
1506038400, 1506124800, 1506211200, 1519862400, 1519948800, 1520035200, 
1520121600, 1520208000, 1520294400, 1520380800), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), yyyy = c(2017, 2017, 2017, 2017, 2018, 2018, 2018, 
2018, 2018, 2018, 2018), mmm = c("Sep", "Sep", "Sep", "Sep", 
"Mar", "Mar", "Mar", "Mar", "Mar", "Mar", "Mar"), dd = c(21, 
22, 23, 24, 1, 2, 3, 4, 5, 6, 7), season = c("Summer", "Summer", 
"Summer", "Summer", "Spring", "Spring", "Spring", "Spring", "Spring", 
"Spring", "Spring"), parameter = c("pm10", "pm10", "pm10", "pm10", 
"pm10", "pm10", "pm10", "pm10", "pm10", "pm10", "pm10"), concentration = c(1.18203524647271, 
0.272779348785041, 2.72734710946683, 1.90901454850886, 1.36318527323721, 
2.09023261562629, 2.81729052990488, 1.27222532200908, 0.999671017356097, 
0.999603793405514, 1.09048875706049)), row.names = c(NA, -11L
), class = c("tbl_df", "tbl", "data.frame"))

Here is the code I use now:

ggplot(data = df2, aes(x = date, y = concentration,col=station )) +geom_line() + facet_wrap(facets = vars(parameter),scales="free",ncol=7)

You can see the result in the following image

I have several questions:

  1. I want to remove the straight line and remove the axis with missing value, only plot the day with value. Can I do that?
  2. Can I draw for a specific parameter (for example Na and Cl only)?
  3. How to edit label on the top of each graph?

Thank you in advance.

AgungGK
  • 85
  • 7
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please just ask one clear question at a time. – MrFlick Jul 09 '20 at 03:08
  • Think this may help https://stackoverflow.com/questions/9617629/connecting-across-missing-values-with-geom-line – David Jul 09 '20 at 03:44
  • Thank you @MrFlick, it is useful. I already attach examples of the data. Is it enough? – AgungGK Jul 09 '20 at 19:07
  • @DavidGibson Thanks for your reply. I have tried this solution in advance and here is the result (https://i.stack.imgur.com/iDYsQ.png). But this is not what I desire. I want to remove the line and remove the x-axis with no data. Probably something similar with what excel can do (https://i.stack.imgur.com/NcS96.png). – AgungGK Jul 09 '20 at 19:20

1 Answers1

0

I already find the solution. Absolutely, R is not accepting a discontinuous data frame, so first of all I need to manipulate data frame with a continuous date and leave the data blank for NA data. The result is something like this

AgungGK
  • 85
  • 7