저는 매일이 점들을 플로팅하려고합니다. 각 패싯 축이 "00:00"에서 "23:59"로 확장되기를 바랍니다.
지금은 각 패싯 x 축이 첫 번째 항목에서 마지막 항목까지 확장되는 것처럼 보이지만 각 패싯 x 축이 "00:00"에서 시작하여 패싯 날짜의 "23:59"에 끝나기를 바랍니다. :
ggplot(minidate, aes(x=time,y=measurement, group=EPC))+
geom_point()+ geom_line()+
facet_wrap(~dateonly,ncol=1)
제한을 사용하여 특정 시간을 지정하려고 시도했지만 scale_x_time
작동하지 않습니다. 깔끔하게 facet_wrap
작업 하길 바랬 group_by
기 때문에 시도해 봤어요
+ scale_x_datetime(limits=
c(as.POSIXct(paste0(unique(minidate$dateonly),"00:00"),format="%Y-%m-%d %H:%M"),
as.POSIXct(paste0(unique(minidate$dateonly),"23:59"),format="%Y-%m-%d %H:%M"))
)
하지만 작동하지 않는 것 같습니다.
zero_range (범위) 오류 : x는 길이 1 또는 2 여야합니다.
다음은 데이터 세트입니다.
dput()
structure(list(time = structure(c(1523883481, 1523883481, 1523883957, 1523883957, 1524059523, 1524059523, 1524059913, 1524059913, 1524138446, 1524138446, 1524138488, 1524138488, 1524139045, 1524139045, 1524139241, 1524139241, 1524139855, 1524139855, 1524139978, 1524139978, 1524215195, 1524215195, 1524215406, 1524215406, 1524230989, 1524230989, 1524231221, 1524231221, 1524309944, 1524309944, 1524310193, 1524310193, 1524323456, 1524323456, 1524324053, 1524324053, 1524385173, 1524385173, 1524385310, 1524385310, 1524403469, 1524403469, 1524403674, 1524403674, 1524403762, 1524403762, 1524403834, 1524403834, 1524473794, 1524473794), class = c("POSIXct", "POSIXt"), tzone = "UTC"), EPC = c("ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081", "ccd10081"), measurement = c("in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out", "out", "in", "in", "out"), dateonly = structure(c(17637, 17637, 17637, 17637, 17639, 17639, 17639, 17639, 17640, 17640, 17640, 17640, 17640, 17640, 17640, 17640, 17640, 17640, 17640, 17640, 17641, 17641, 17641, 17641, 17641, 17641, 17641, 17641, 17642, 17642, 17642, 17642, 17642, 17642, 17642, 17642, 17643, 17643, 17643, 17643, 17643, 17643, 17643, 17643, 17643, 17643, 17643, 17643, 17644, 17644), class = "Date")), row.names = c(1L, 146L, 2L, 147L, 3L, 148L, 4L, 149L, 5L, 150L, 6L, 151L, 7L, 152L, 8L, 153L, 9L, 154L, 10L, 155L, 11L, 156L, 12L, 157L, 13L, 158L, 14L, 159L, 15L, 160L, 16L, 161L, 17L, 162L, 18L, 163L, 19L, 164L, 20L, 165L, 21L, 166L, 22L, 167L, 23L, 168L, 24L, 169L, 25L, 170L ), class = "data.frame")
를 사용하는 동안 일일 시간 제한을 어떻게 설정 facet_wrap(~day)
합니까?
한 가지 접근 방식은 모든 시간이 같은 날에있는 플로팅을위한 도우미 datetime 열을 만드는 것입니다. 이것의 장점은 ggplot의 중단 및 날짜 시간 레이블링을 활용한다는 것입니다.
library(dplyr); library(lubridate); library(stringr)
minidate %>%
mutate(time_only = ymd_hms(paste("1900-01-01",
str_sub(time, 12)))) %>%
ggplot(aes(x=time_only,y=measurement, group=EPC))+
geom_point()+ geom_line()+
expand_limits(x = c(ymd_h(1900010100), ymd_h(1900010200))) +
scale_x_datetime(date_labels = "%H:%M") +
facet_wrap(~dateonly,ncol=1)
또는 datetimes를 시간을 나타내는 10 진수 값으로 변환 할 수 있습니다.
library(dplyr); library(lubridate)
minidate %>%
mutate(time_dec = hour(time) + minute(time)/60 + second(time)/3600) %>%
ggplot(aes(x=time_dec,y=measurement, group=EPC))+
geom_point()+ geom_line()+
expand_limits(x = c(0, 24)) +
facet_wrap(~dateonly,ncol=1)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다