我正在创建一个时间表图,以显示每个时间块中有多少事件.我已经从lubridate计算了所有这些信息,并且可以在ggplot上绘制它.但我需要反转/翻转轴,以便顶部显示早上8点,然后下午5点而不是下午5点到早上8点.
这就是我目前最终结果的片段.只需要颠倒时间顺序就可以完美.这延长了上午8点至下午5点和MF.
我尝试使用scale_y_reverse,但这不起作用.
我看到这篇文章,但我无法弄清楚如何在我的情况下使用它:ggplot中的反向日期时间(POSIXct数据)轴
示例数据(使用dput fn创建):
df <- structure(list(ID = c(4108L, 4165L, 1504L, 2570L, 1523L, 2556L,
3224L, 1503L, 3220L, 837L), START_TIME = structure(c(1504267200,
1504281600, 1504258200, 1504278000, 1504263600, 1504256400, 1504258200,
1504274400, 1504258200, 1504256400), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), END_TIME = structure(c(1504270799, 1504285199,
1504263599, 1504281599, 1504268999, 1504259999, 1504263599, 1504279799,
1504263599, 1504259999), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Day = structure(c(5L, 5L, 2L, 3L, 2L, 3L, 4L, 2L, 4L, 1L), .Label = c("M",
"T", "W", "R", "F"), class …Run Code Online (Sandbox Code Playgroud) 我正在使用ggplot2创建一系列图。每一个都是以编程方式命名的,我想使用这些名称为每个人提供自己的图形标题。我想从列表中提取名称并将它们动态传递给 fig.cap。
有没有办法做到这一点?这是一个 MCVE,您可以在列表和单个图之间切换以查看数字消失或显示:
---
output: pdf_document
---
```{r, include = FALSE}
library(ggplot2)
library(knitr)
opts_chunk$set(echo=FALSE)
```
```{r}
## Plot 1
listOfPlots <- list(
# Plot 1
ggplot(data = diamonds) +
geom_point(aes(carat, price)),
## Plot 2
ggplot(data = diamonds) +
geom_point(aes(carat, depth))
)
names(listOfPlots) <- c("This is caption 1", "This is caption 2")
```
```{r, fig.cap = c("This is caption 1", "This is caption 2"), echo=TRUE}
listOfPlots
# listOfPlots$`This is caption 1`
# listOfPlots$`This is caption 2`
```
Run Code Online (Sandbox Code Playgroud)
笔记: …