-1

I got a df looking like this:

'my_data':   365 obs. of  5 variables:
$ Day      : chr  "01" "02" "03" "04" ...
$ Month    : Factor w/ 12 levels "01","02","03",..: 1 1 1 1 1 1 1 1 1 1 ... [[[Range: 1 to 12]]]
$ Year     : chr  "2019" "2019" "2019" "2019" ...
$ XXX      : int  2 4 5 5 7 6 6 7 6 6 ... [[[Range: 1 to 9]]]
$ Weekday  : Factor w/ 7 levels "Monday","Tuesday",..: 2 3 4 5 6 7 1 2 3 4 ...

Currently I am trying go get a graph in ggplot which shows all values for $ XXX which are <= 3 and >= 7 for the whole year. How can I define, that the days fit to the individual months and have to be seen consecutively?

Any help would be appreciated,

Thanks!

dc37
  • 15,840
  • 4
  • 15
  • 32
Eurastas
  • 23
  • 1
  • 3
  • Can you provide a reproducible example of your dataset (https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? – dc37 Feb 29 '20 at 23:45
  • (1) Create real `Date`s, look for `paste` and `as.Date`. (2) See `ggplot2::scale_x_date` for axis label formatting. (3) Which are between 3 and 7 for the whole year? Sounds like `dplyr::filter` (since you said `dplyr`), is there something more than filter? – r2evans Mar 01 '20 at 00:02

1 Answers1

0

Without an example of your dataset, it is hard to be sure what is the solution of your problem, what you can do is to use lubridate and try:

library(lubridate)
my_data$Date_full <- ymd(paste(c(Year, Month, Day), sep = "-"))

For plotting part, you can subset the dataset:

library(ggplot2)
ggplot(subset(my_data, XXX =< 3 & XXX >= 7), aes(x = Date_Full, y = XXX))+
   geom_point()

Does it answer your question ?

If this is not working please provide a reproducible example of your dataset (see this link: How to make a great R reproducible example)

dc37
  • 15,840
  • 4
  • 15
  • 32
  • Thank you! That worked :) And thank you for the link on how to create an REPEX, ill keep it in mind if I should have another question. – Eurastas Mar 03 '20 at 18:51