作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 scale_x_continuous
缩小 ggplot 上的超前/滞后空间。它适用于数字 x 轴对象。然而,我对约会没有任何兴趣。
我的例子:
library(lubridate)
library(tidyverse)
# this works
ggplot(cars, aes(x = speed, y = dist)) +
geom_line() +
scale_x_continuous(expand = c(0, 0))
# this does not work
cars %>%
mutate(date = seq(dmy("01/01/2019"), dmy("01/01/2019") + ddays(nrow(cars) - 1), "day")) %>%
ggplot(aes(x = date, y = dist)) +
geom_line() +
scale_x_continuous(expand = c(0, 0))
有什么想法吗?
最佳答案
在 X 轴上,您正在处理 date
类型的数据,而不是 continuous
数据。
您可以使用以下代码
cars %>%
mutate(date = seq(dmy("01/01/2019"), dmy("01/01/2019") + ddays(nrow(cars) - 1), "day")) %>%
ggplot(aes(x = date, y = dist)) +
geom_line() +
scale_x_date(expand = c(0, 0))
产生以下情节
关于r - 如何减少日期的ggplot中x轴的超前/滞后空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56661545/
我有跟踪数据,我使用 LEAD 和 LAG 修改开始和结束日期,以确保上一个结束时间等于下一个开始时间。这些查询在 groupId 上进行分区,按开始时间排序。 我的问题是当其中一条记录的开始和结束时
我需要使用多个领先和滞后从数据集中计算附加功能。大量超前和滞后会导致内存不足错误。 数据框: |----------+----------------+---------+---------+----
场景: ticket 有 StartDate 和 EndDate ,如果 StartDate 和 EndDate 存在,则创建一个新的数据框作为在下面显示所需的输出。 Pyspark 数据集如下所示
我是一名优秀的程序员,十分优秀!