0

我已经查看了有关此错误的一些流行主题,但似乎没有一个对我有帮助。

我正在处理数据,试图创建一个折线图,其中 x 上的日期和线条代表三个变量,即出勤率 (int)、注册人 (int) 和 No.Show (int)。我试过 as.numeric 但这似乎没有做任何事情。

这是我的代码:

IHS %>%
  filter(Start.Date != "2020-11-13", Start.Date != "2021-01-08", Start.Date != "2021-01-15", Start.Date != "2021-05-07") %>% 
  filter(Template != "Campus Event - IHS Tour (VIRTUAL)") %>%
ggplot(aes(x = Start.Date)) +
  geom_line(aes(y = Registrants, color = "Registrants")) +
  geom_line(aes(y = Attendance, color = "Attendance")) +
  geom_line(aes(y = No.Show, color = "No.Show")) +
  theme_classic() +
  annotate("rect", xmin = as.Date("2020-11-20"), xmax = as.Date("2021-01-22"), ymin = 0, ymax = 14,
  alpha = .09) + 
  annotate("text", x = as.Date("2020-11-20"), y = 12, label = "No tours\nduring holiday", hjust = -1, vjust = 0.5, size = 3) +
  annotate("text", x = as.Date("2021-04-09"), y = 26, label = "26", hjust = .5, vjust = -.9, size = 3) +
  annotate("text", x = as.Date("2021-04-09"), y = 15, label = "15", hjust = .5, vjust = -.9, size = 3) +
  annotate("text", x = as.Date("2021-04-09"), y = 11, label = "11", hjust = .5, vjust = -.9, size = 3) +
  labs(x = "Date", y = "Count")+
  ggtitle("IHS Tour Registrants, Attendance, and No Show") +
  scale_x_continuous(limits = as.Date(c("2020-09-11","2021-04-30")), breaks = as.Date(c("2020-09-11", "2020-09-18", "2020-09-25", "2020-10-02", "2020-10-02", "2020-10-11", "2020-10-16", "2020-10-23", "2020-10-30", "2020-11-06", "2020-11-06", "2020-11-20", "2020-11-06", "2021-01-22", "2021-01-29", "2021-02-05", "2021-02-12",  "2021-02-26", "2021-03-05", "2021-03-12", "2021-03-19", "2021-03-26", "2021-04-09",  "2021-04-16", "2021-04-23", "2021-04-30", "2021-04-30"))) +
  scale_color_manual(name = "Legend", values = c("#FF8000", "#7A1F2E", "#006699")) +
    scale_y_continuous(limits = c(0,27), breaks = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,19,20,21,
                                  22, 23, 24, 25, 26, 27)) +
  theme(axis.title.y = element_text(angle = 0, vjust = .5)) +
    theme(legend.position = "top") +
  theme(axis.title.x = element_text(size=10, face = "bold"),
        axis.text.x  = element_text(size=10, angle = 90), 
        axis.text.y = element_text(angle = 0, size = 9), 
        axis.title.y = element_text(angle=0, size = 10, vjust = .5, face = "bold")) 

我知道发生了很多事情,如果这更容易的话,我可以将其浓缩,但我认为,因为我似乎无法确定出了什么问题,所以整个代码块都是好的。

该图在某一点上很好,我能够产生这个: 图形

但是当我尝试重新运行代码时,图表开始给我关于提供给连续刻度的离散值的错误。

4

0 回答 0