代码之家  ›  专栏  ›  技术社区  ›  SNT

ggplot:as中的错误。日期数字(值):“来源”必须提供

  •  0
  • SNT  · 技术社区  · 7 年前

    我有一个数据集,我正试图用它来绘制 ggplot geofacet .以下是我的数据样本:

    # A tibble: 6 x 3
      date       actuals_vol geo  
      <date>           <dbl> <chr>
    1 2014-02-02    9607815. AK   
    2 2014-02-09    9552680. AK   
    3 2014-02-16    9251645. AK   
    4 2014-02-23    9177905  AK   
    5 2014-03-02    9254805  AK   
    6 2014-03-09    9222940. AK   
    

    这是我用来在平铺图中绘制数据的代码:

    ggplot(cig_prophet_states, aes(date, actuals_vol)) +
      geom_area(fill='#114365') +
      facet_geo(~ geo, grid = "us_state_grid2", label="name") +
      scale_x_continuous(labels = function(x) paste0("'", substr(x, 3, 4))) +
      labs(title = "GDP by State 1997-2016 ($, trillions)",
           caption = "Data Source: St. Louis FRED",
           x = "Year",
           y = "volume") +
      theme(strip.text.x = element_text(size = 8))
    

    我得到以下错误: Error in as.Date.numeric(value) : 'origin' must be supplied

    1 回复  |  直到 7 年前
        1
  •  3
  •   stevec Zxeenu    6 年前

    简单使用 scale_x_date 而不是 scale_x_continuous

    ggplot(cig_prophet_states, aes(date, actuals_vol)) +
      geom_area(fill='#114365') +
      facet_geo(~ geo, grid = "us_state_grid2", label="name") +
      scale_x_date(labels = function(x) paste0("'", substr(x, 3, 4))) +
      labs(title = "GDP by State 1997-2016 ($, trillions)",
           caption = "Data Source: St. Louis FRED",
           x = "Year",
           y = "volume") +
      theme(strip.text.x = element_text(size = 8))
    
    推荐文章