我有一个数据集,我正在尝试使用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
答案 0 :(得分:1)
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))