У меня проблемы с попыткой заставить ось X на моем ggplot показывать только определенные значения.Ось X - это диапазон времен, однако в настоящий момент их так много, что они не читаются (см. Изображение), в идеале я хотел бы один тик каждый час или около того, но я просто не могу понять, как это сделать.
Любые предложения были бы невероятно оценены.
Я пробовал предложения по подобным проблемам, и мне не повезло (см. Ниже большинство кодов, которые я пробовал, и ошибки)
Это код моего графика;
ggplot(data, aes(x=time, y=binary)) +
geom_bar(stat='identity') +
facet_wrap(~id,scales="free_x", ncol=1,strip.position = "right")
![this is what the graph currently looks like](https://i.stack.imgur.com/My7ua.jpg)
и вот большинство вещей, которые я пытался решить,
scale_x_continuous(breaks=c(seq(16:00,17:00,18:00)))
>Error in seq.default(16:0, 17:0, 18:0, :
'from' must be of length 1
In addition: Warning message:
In seq.default(16:0, 17:0, 18:0,) :
extra arguments will be disregarded
scale_x_continuous(breaks=c(seq("16:00","17:00","18:00")))
> Error in seq.default("16:00", "17:00", "18:00") :
'from' must be a finite number
In addition: Warning message:
In seq.default("16:00", "17:00", "18:00") : NAs
введено по принуждению
data$time <- gsub('\"', "", as.character(data$time), fixed=TRUE)
data$time <- as.Date(data$time, "%H-%M-%S")
> Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf
4: Removed 7290 rows containing missing values (position_stack).
x=data$time
as.numeric(gsub(",","",x,fixed=TRUE))
> Warning message:
NAs introduced by coercion
scale_x_datetime(breaks = date_breaks("1 hour"), labels = date_format("%H:%M:%S"))
<ScaleContinuousDatetime>
Range:
Limits: 0 -- 1
Вот пример исходного набора данных (он огромен), извиняюсь за то, что не опубликовал его изначально.Большое спасибо за помощь!
> data
time id binary
1 15:49 267 2
2 13:58 269 0
3 15:51 231 0
4 16:00 263 1
5 15:51 237 2
6 15:53 236 2
7 16:00 235 2
> dput(data)
structure(list(time = structure(c(2L, 1L, 3L, 5L, 3L, 4L, 5L), .Label = c("13:58",
"15:49", "15:51", "15:53", "16:00"), class = "factor"), id = c(267L,
269L, 231L, 263L, 237L, 236L, 235L), binary = c(2L, 0L, 0L, 1L,
2L, 2L, 2L)), .Names = c("time", "id", "binary"), class = "data.frame", row.names = c(NA,
-7L))
> str(data)
'data.frame': 7 obs. of 3 variables:
$ time : Factor w/ 5 levels "13:58","15:49",..: 2 1 3 5 3 4 5
$ id : int 267 269 231 263 237 236 235
$ binary: int 2 0 0 1 2 2 2