date - dealing with the Lables using the function of scale_x_datetime in ggolot2 in R -


i have problems looks simple, not figure out, when used function of scale_x_datetime. please the graphs below: enter image description here

what want in graph:

1) x label time (for example: 00:00:00) 2) first value of x label should 00:00:00

for first point, used scale_x_datetime(date_labels = "%x") time date_time. got graph below:

enter image description here

the line looks correct first graph, responding x-axis value wrong.

for second point want get, tried use function limits in scale_x_datetime, not work @

someone has tips it?

thanks lot

note:

to generate data table:

dd <- data.table(date = c("2015-07-01 00:15:00", "2015-07-01 00:30:00", "2015-07-01 00:45:00","2015-07-01 01:00:00", "2015-07-01 01:15:00","2015-07-01 01:30:00","2015-07-01 01:45:00","2015-07-01 02:00:00","2015-07-01 02:15:00", "2015-07-01 02:30:00"),value = c(1.83,1.68,1.29,14.23,0.96, 1.29,10.4,8.25,6.77,7.66))  dd$date<-as.posixct(dd$date) 

for first graph: used code below:

p22 <- ggplot(dd, aes(dd$date, dd$value))+labs(x="time", y="seconds") p22 <-p22 + geom_line(colour="dark blue",size=1)  p22<- p22+scale_x_datetime(date_breaks  = "15 mins") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) 

it looks fine, want show time , added code date_labels = "%x" time value date_time : below:

p22 <- ggplot(dd, aes(dd$date, dd$value))+labs(x="time", y="seconds") p22 <-p22 + geom_line(colour="dark blue",size=1)  p22<- p22+scale_x_datetime(date_breaks  = "15 mins",date_labels = "%x") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) 

and then, got error, since responding x value in second graph wrong. problem of timezone, not sure it.

add vjust = 0.5 want in either case.

library(dplyr) library(ggplot2)  dd = data_frame(   date = c("2015-07-01 00:15:00", "2015-07-01 00:30:00", "2015-07-01 00:45:00","2015-07-01 01:00:00", "2015-07-01 01:15:00","2015-07-01 01:30:00","2015-07-01 01:45:00","2015-07-01 02:00:00","2015-07-01 02:15:00", "2015-07-01 02:30:00"),   value = c(1.83,1.68,1.29,14.23,0.96, 1.29,10.4,8.25,6.77,7.66)   ) %>%    mutate(     as.posixct(date)   ) %>%    ggplot(aes(x = date, y = value)) +    labs(x = "time", y = "seconds") +   geom_line(colour = "dark blue", size = 1) +    scale_x_datetime(date_breaks  = "15 mins") +    theme_bw() +    theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -