0

我有数据,我将其命名为“mytransaction.plot”

datex <- c(rep("2021-07-23", 19), rep("2021-07-24", 21), rep("2021-07-25", 17),
           rep("2021-07-26", 19), rep("2021-07-27", 16), rep("2021-07-28", 17),
           rep("2021-07-29", 14), rep("2021-07-30", 17), rep("2021-07-31", 17))
hourx <- c(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,2,4,5,7,8,9,10,11,12,13,14,16,17,18,20,21,22,0,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,10,11,12,13,14,15,16,18,19,21,22,23,0,1,2,9,10,11,12,13,14,15,16,17,18,19,20,21,22,2,6,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)
transaction <- c(3,9,7,18,5,3,6,9,7,9,4,5,9,14,3,5,1,1,2,2,2,2,2,1,1,1,1,2,6,4,8,6,3,4,2,2,3,3,2,1,1,2,1,1,4,1,2,4,5,1,4,2,7,4,1,1,2,1,1,3,3,3,8,9,23,87,150,171,120,52,4,5,2,5,6,4,2,1,4,4,9,5,7,5,7,6,8,5,9,4,6,6,3,2,4,5,10,6,7,5,9,5,7,5,9,11,8,2,1,2,1,2,8,16,12,15,8,1,2,3,1,4,11,16,13,4,2,4,12,9,7,11,16,15,15,14,8,7,5,1,1,1,3,2,3,2,18,16,11,9,1,12,15,16,6,4,2)
mytransaction.plot <- data.frame(datex, hourx, transaction)

这里的图表: 在此处输入图像描述

这是我的其他数据,我将其命名为“mytransaction.dot”。

datex <- rep("2021-07-26", 6)
hourx <- 12:17
transaction <- c(23,87,150,171,120,52)
mytransaction.dot <- data.frame(datex, hourx, transaction)

问题是,我如何将来自 mytransaction.dot 的交易数据添加到来自 mytransaction.plot 的图表中,但使用 ggplot2 使用 Dot Appearance。结果将是:

在此处输入图像描述

非常感谢你!!!

4

1 回答 1

2

图书馆

library(tidyverse)
library(lubridate)

数据

线

datex <- c(rep("2021-07-23", 19), rep("2021-07-24", 21), rep("2021-07-25", 17),
           rep("2021-07-26", 19), rep("2021-07-27", 16), rep("2021-07-28", 17),
           rep("2021-07-29", 14), rep("2021-07-30", 17), rep("2021-07-31", 17))
hourx <- c(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,2,4,5,7,8,9,10,11,12,13,14,16,17,18,20,21,22,0,1,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,10,11,12,13,14,15,16,18,19,21,22,23,0,1,2,9,10,11,12,13,14,15,16,17,18,19,20,21,22,2,6,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)
transaction <- c(3,9,7,18,5,3,6,9,7,9,4,5,9,14,3,5,1,1,2,2,2,2,2,1,1,1,1,2,6,4,8,6,3,4,2,2,3,3,2,1,1,2,1,1,4,1,2,4,5,1,4,2,7,4,1,1,2,1,1,3,3,3,8,9,23,87,150,171,120,52,4,5,2,5,6,4,2,1,4,4,9,5,7,5,7,6,8,5,9,4,6,6,3,2,4,5,10,6,7,5,9,5,7,5,9,11,8,2,1,2,1,2,8,16,12,15,8,1,2,3,1,4,11,16,13,4,2,4,12,9,7,11,16,15,15,14,8,7,5,1,1,1,3,2,3,2,18,16,11,9,1,12,15,16,6,4,2)
mytransaction.plot <-
   data.frame(datex, hourx, transaction) %>% 
   mutate(datex = ymd(datex),
          #Create datetime object with datex + hourx
          datetime = ISOdatetime(
             year = year(datex),
             month = month(datex),
             day = day(datex),
             hour = hourx,
             min = 0,
             sec = 0))

观点

datex <- rep("2021-07-26", 6)
hourx <- 12:17
transaction <- c(23,87,150,171,120,52)
mytransaction.dot <-
   data.frame(datex, hourx, transaction) %>% 
   #Transform datex to date
   mutate(datex = ymd(datex),
          #Create datetime object with datex + hourx
          datetime = ISOdatetime(
             year = year(datex),
             month = month(datex),
             day = day(datex),
             hour = hourx,
             min = 0,
             sec = 0))

阴谋

mytransaction.plot %>%
   ggplot(aes(datetime,transaction))+
   # Add line
   geom_line()+
   # Add point, with data.frame mytransaction.dot
   geom_point(data = mytransaction.dot)

输出

在此处输入图像描述

于 2021-09-02T14:52:35.057 回答