a <-4
b<- 1
c<-0
set.seed(1)
wheat <- rnorm(128,a,b)
hazelnut <- runif(128, min = -4, max = 1)
corn <- rnorm(128,c,b)
DAY <- seq(as.Date("2018-03-01"),as.Date("2018-07-06"),by="day")
df<- data.frame(wheat,hazelnut,corn,DAY)
ggplot(data=df, aes(x=wheat,y=DAY)) geom_point(color="orange")
ggplot(data=df, aes(x=hazelnut,y=DAY)) geom_point(color="blue")
ggplot(data=df, aes(x=corn,y=DAY)) geom_point(color="red")
how to repeat the above plot with only two months data. I did plot with all data but I can't make a plot only 2 months with previous plots.
CodePudding user response:
require(ggplot2)
require(tidyverse)
df %>%
mutate(month = month(DAY)) %>%
filter(between(month, 3, 4)) %>%
ggplot()
aes(wheat, DAY)
geom_point()
Together:
df %>%
gather(-DAY, key = "type", value = "value") %>%
mutate(month = month(DAY)) %>%
filter(between(month, 3, 4)) %>%
ggplot()
aes(value, DAY)
geom_point()
facet_wrap(~ type, scales = "free_x")