r - ggplot:as.Date.numeric(value) 中的错误:必须提供“原点”
问题描述
我有一个数据集,我正在尝试使用ggplot
and来绘制它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
解决方案
只需使用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))
推荐阅读
- javascript - Mongoose Populate 获取用户的所有帖子返回空数组
- macos - 使用 Apple 的 Catalyst 转换为 Mac 时的问题
- php - laravel 选中复选框时非法运算符和值组合
- gradle - assembleRelease.dependsOn 测试所有项目
- python - 在后缀转换中实现错误(python)
- ios - 快速网络和响应序列化
- python - 将数字添加到python列表中的字符串
- c# - 在外部用户控件之间切换
- selenium - Selenium Python,从节点和所有子节点中提取文本
- ruby-on-rails - Sidekiq:“发生异常:无法分配线程”