Line break when no data in ggplot2

后端 未结 3 977
猫巷女王i
猫巷女王i 2020-11-27 05:13

I am using R to plot some data.

Date <- c(\"07/12/2012 05:00:00\", \"07/12/2012 06:00:00\", \"07/12/2012 07:00:00\",
      \"07/12/2012 08:00:00\",\"07/         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 06:05

    Juba's answer, to include explicit NA's where you want breaks, is the best approach. Here is an alternate way to introduce those NA's in the right place (without having to figure it out manually).

    every.hour <- data.frame(Date=seq(min(Date), max(Date), by="1 hour"))
    df2 <- merge(df1, every.hour, all=TRUE)
    g %+% df2
    

    enter image description here

    You can do something similar with your later df example, after changing the dates and times into a proper format

    df$DateTime <- as.POSIXct(strptime(paste(df$Date, df$Time), 
                                       format="%m/%d/%Y %H:%M:%S"))
    every.ten.seconds <- data.frame(DateTime=seq(min(df$DateTime), 
                                                 max(df$DateTime), by="10 sec"))
    df.10 <- merge(df, every.ten.seconds, all=TRUE)
    

提交回复
热议问题