df1 <- structure(list(Index = 1:11, Duration = structure(c(1487577655,
1487577670, 1487577675, 1487577680, 1487577685, 1487577680, 1487577700,
1487577705, 1487577695, 1487577700, 1487577680), class = c("POSIXct",
"POSIXt"), tzone = "")), .Names = c("Index", "Duration"), class = "data.frame", row.names = 3:13)
現在我構造圖如下:
g1 <- ggplot(df1, aes(x=Index, y=Duration, color=Duration))+
geom_point()+
geom_line()+
scale_y_datetime(labels=date_format("%M:%S"))
因爲它是現在,圖形的顏色設置爲默認的「黑「到」藍色「漸變。
問題是,我試圖給數據分配自定義漸變時出現錯誤。
對於非POSIXct對象:
scale_color_gradient("Duration",low="#D80427", high="#07a0ff",space="Lab")
作品,但我得到下面的錯誤與POSIXct對象df1$Duration
作爲解釋變量:
錯誤Ops.POSIXt((X - from [1]),diff(from)):'/'未定義 for「POSIXt」objects
是否有不同的梯度函數當我繪製一個POSIXct對象時,我需要使用它嗎?
嘗試'顏色= as.numeric(持續時間))' – zx8754