[R] Axis whitout all the row, that contains time

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Feb 14 09:52:31 CET 2021


Hello,

It's not scale_x_time with arguments breaks and labels.

It's scale_x_datetime with arguments

date_breaks and date_labels.
If you also want the hour displayed in the x axis labels, change the 
format string in my previous post to


scale_x_datetime(date_breaks = "20 secs", date_labels = "H:%M:%S")


Can you post as data sample the output of dput?

dput(head(listeMesuresPropres, 20))  # or 30


Hope this helps,

Rui Barradas

Às 07:35 de 14/02/21, Informatique escreveu:
> Hello,
> 
> the time are in the first table like that :	10:24:00
> and i use this for
> 	listeMesuresPropres$Heure. <- hms(listeMesuresPropres$Heure.
> after time ar like that : 		10H 24M 0S
> and when i use  with ggplot
>    scale_x_time(breaks = "20 secs",labels = "%H:%M:%S")
> 
> it have the graphics but noting write on the X axis.
> 
> I think it a problem with the format of the time, because if i try a ggplot without scale_x_time i don't have anything on the graphic.
> 
> Thank's
> 
> François-Marie BILLARD
> 
> On Fri, 12 Feb 2021 18:24:35 +0000
> Rui Barradas <ruipbarradas using sapo.pt> wrote:
> 
>> Hello,
>>
>> In order to select every 20 s, set the date_breaks = "20 secs", not the
>> breaks.
>> The axis labels are also formatted, with date_labels, standard datetime
>> format strings are used for this. And rotated, not part of the question.
>>
>> # Create some data
>> set.seed(2021)
>> time <- seq(as.POSIXct("2021-02-11"), as.POSIXct("2021-02-11 00:29:59"),
>> by = "1 secs")
>> y <- cumsum(rnorm(length(time)))
>> df1 <- data.frame(time, y)
>>
>> # Plot the data
>> library(ggplot2)
>>
>> ggplot(df1, aes(time, y)) +
>>     geom_line() +
>>     scale_x_datetime(date_breaks = "20 secs", date_labels = "%M:%S") +
>>     theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1,
>> size = 5))
>>
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>> Às 15:05 de 12/02/21, Informatique escreveu:
>>> Hello,
>>>
>>> i'm using Rstudio from a few day, and i have some information in a CVS file, take every five second, format of the time is HH:MM:SS.
>>> I use the hour on the X axis, but i don't want having all the time print. For example only every 10 values.
>>>
>>> I think it will be possible with   scale_x_datetime(breaks = date_breaks(XXX)
>>>
>>> but i don't understand how select every 20 s.
>>>
>>> Thank's for your help
>>>
>>> François-marie BILLARD
>>>
> 
>



More information about the R-help mailing list