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")
如何僅用兩個月的資料重復上述情節。我確實用所有資料繪制了圖,但我不能只用以前的圖繪制 2 個月的圖。
uj5u.com熱心網友回復:
require(ggplot2)
require(tidyverse)
df %>%
mutate(month = month(DAY)) %>%
filter(between(month, 3, 4)) %>%
ggplot()
aes(wheat, DAY)
geom_point()
一起:
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")
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460013.html
下一篇:在一列中具有相同值的值的交叉刺激
