我正在嘗試繪制后續圖的完整性,r但我在以正確格式繪制日期時遇到 x 軸問題,盡管我使用正確的格式將其放入資料集中POSIXct
我的代碼和示例資料集:
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
結果圖如下所示。我做了很多
uj5u.com熱心網友回復:
我不確定它是否是您需要的,但是,根據您的資料集,我假設您想查看 x 軸上的分鐘數,因為天數和小時數彼此相似。
使用minutefromlubridate包,您可以以適當的方式更改 x 軸。
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
通過使用不同的包,ggplot2我們可以產生類似的圖。
在繼續之前,我更新了 Data.Inverventon 以代表不同的年份。然后使用包中的as.yearmon函式創建 yearmonth 變數zoo。
Date.Interventon = as.POSIXct('1/27/2017', format='%m/%d/%Y') 1:40*60000000
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)
data.fu.lorenzoo$yearmonth = zoo::as.yearmon(data.fu.lorenzoo$Date.Interventon)
然后你可以繪制一個類似的圖形
ggplot(data.fu.lorenzoo, aes(x = yearmonth, y = OS.years, color = Status))
geom_point() geom_smooth(method = lm, se = FALSE)
labs( x = "Date of procedure", y = "Follow-up (years)")
theme_minimal()
輸出是這樣的

uj5u.com熱心網友回復:
可能不是最好的解決方案,您需要單獨格式化軸。
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))

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/372291.html
