由于标准的明确格式错误,无法在ggplot中绘制数据

时间:2016-04-08 17:05:13

标签: r ggplot2

您好我在运行此代码时收到错误“错误:字符串不是标准的明确格式”。我觉得这是因为日期格式的问题。有人可以帮忙解决这个问题。

      library(ggplot2)
      library(ggmap)
      library(dplyr)
      library(readr)
      library(lubridate)


      coltypes <-
        list(Dates = col_datetime("%Y-%m-%d %H:%M:%S"))

      map <- read.csv(file.choose(),header=T)

      map <-
        read_csv(map,
                 col_types=coltypes)

      mapdata <-
        map %>%
        filter(Category %in% c("LARCENY/THEFT", "ASSAULT", "DRUG/NARCOTIC"))

      train <-
        map %>%
        mutate(Year  = factor(year(Dates), levels=2003:2015),
               Month = factor(month(Dates), levels=1:12),
               Day   = day(Dates),
               Hour  = factor(hour(Dates), levels=0:23),
               dayDate = as.POSIXct(round(Dates, units = "days")),
               DayOfWeek = factor(DayOfWeek, levels=c("Monday",
                                                      "Tuesday",
                                                      "Wednesday",
                                                      "Thursday",
                                                      "Friday",
                                                      "Saturday",
                                                      "Sunday"))
        )

      unique(train$Category)

      ggplot(data=mapdata, aes(x=Hour)) +
        geom_bar(colour="black", fill="skyblue") +
        ylab('Count') +
        facet_wrap(~Category, scales='free')+
        theme(axis.text.x = element_text(angle = 90, hjust = 1))

0 个答案:

没有答案