Home > database >  How to plot date in a proper format in x-axis in the completeness of the follow-up plot in r car pac
How to plot date in a proper format in x-axis in the completeness of the follow-up plot in r car pac

Time:12-02

I am trying to plot the completeness of the follow-up plot in r but I am experiencing a problem with x-axis in plotting date in a proper format although I put it in the correct format in the dataset using POSIXct

My code and sample dataset:

Date.Interventon = as.POSIXct('1/27/2017', format='%m/%d/%Y')   1:40*60
Status<- c ("Alive","Dead","Dead","Dead","Alive","Alive","Dead","Dead","Alive","Dead")
OS.years <-c(11,13,14,13,13,10,13,14,10,11)
data.fu.lorenzoo= data.frame(Date.Interventon,Status, OS.years)

str(Date.Interventon )
library(car)
scatterplot( OS.years ~ Date.Interventon | Status, data=data.fu.lorenzoo, 
             xlab = "Date of procedure",
             ylab = "Follow-up (years)", 
             smooth = F,  # Removes smooth estimate
             regLine = T) # Removes linear estimate


The resulting plot is shown below. I did many enter image description here

CodePudding user response:

I am not sure that it is what you need but, from your dataset, I assume that you want to see the minutes in x axis, because days and hours are similar to each other.

with using minute from lubridate package, you can change your x-axis in a proper way.

car::scatterplot( OS.years ~ minute( Date.Interventon) | Status, data=data.fu.lorenzoo, 
        xlab = "Date of procedure",
        ylab = "Follow-up (years)", 
        smooth = F,  # Removes smooth estimate
        regLine = T) # Removes linear estimate

CodePudding user response:

Probably not the best solution, you need separately format the axis.

Date.Interventon = as.POSIXct("1/27/2017", format="%m/%d/%y")   1:40*60
    Status<- c ("Alive","Dead","Dead","Dead","Alive","Alive","Dead","Dead","Alive","Dead")
    OS.years <-c(11,13,14,13,13,10,13,14,10,11)
    
    data.fu.lorenzoo= data.frame(Date.Interventon, Status, OS.years)
    
    
    
    
    library(car)
    scatterplot( OS.years ~ Date.Interventon| Status, data=data.fu.lorenzoo, 
                 xlab = "Date of procedure",
                 ylab = "Follow-up (years)", 
                 smooth = F,  # Removes smooth estimate
                 regLine = T,
                 axes=F) # Removes linear estimate
    axis(2)
    axis(1, Date.Interventon, format( as.POSIXct("1/27/2017", format="%m/%d/%y")   1:40*60, cex.axis = .7))

enter image description here

  • Related