数据:
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
作为解释变量时出现以下错误:
Error in Ops.POSIXt((x - from[1]), diff(from)) : '/' not defined for "POSIXt" objects
当绘制POSIXct对象的图形时,是否需要使用不同的梯度函数?
color = as.numeric(Duration)
。 - zx8754