1 主な使い方

すごく使える気はするのですが、たまたま今日見つけたばかりなのでまだよく分かりません。今後調べてみようロ思います。 mpr_request( slugIDs = NULL, slugIDs_legacy = NULL, report_time = NULL, message = TRUE )

beef<- usdampr::mpr_request(slugIDs_legacy = 'LM_CT100', report_time = '2021:2022')
## Successfully requested data for slug: 2466 
## Multiple sections are included in the data list:
##  1-Summary.
##  2-Detail.
##  3-History.
beef2 <- beef$Detail

head(beef2)
##   report_date previous_day_head_count same_day_prev_week_head_count
## 1  2021-12-30                    5039                         17486
## 2  2021-12-30                    5039                         17486
## 3  2021-12-30                    5039                         17486
## 4  2021-12-30                    5039                         17486
## 5  2021-12-30                    5039                         17486
## 6  2021-12-30                    5039                         17486
##   same_day_prev_year_head_count current_week_head_count
## 1                         28780                   56844
## 2                         28780                   56844
## 3                         28780                   56844
## 4                         28780                   56844
## 5                         28780                   56844
## 6                         28780                   56844
##   previous_week_head_count previous_year_head_count
## 1                    29765                    30606
## 2                    29765                    30606
## 3                    29765                    30606
## 4                    29765                    30606
## 5                    29765                    30606
## 6                    29765                    30606
##                                                                       narrative
## 1 **This report will not be published Friday, 12/31/21 due to Federal Holiday**
## 2 **This report will not be published Friday, 12/31/21 due to Federal Holiday**
## 3 **This report will not be published Friday, 12/31/21 due to Federal Holiday**
## 4 **This report will not be published Friday, 12/31/21 due to Federal Holiday**
## 5 **This report will not be published Friday, 12/31/21 due to Federal Holiday**
## 6 **This report will not be published Friday, 12/31/21 due to Federal Holiday**
##   class_description selling_basis_description grade_description head_count
## 1     ALL BEEF TYPE         DRESSED DELIVERED  Total all grades       1093
## 2     ALL BEEF TYPE               DRESSED FOB  Total all grades        785
## 3     ALL BEEF TYPE            LIVE DELIVERED  Total all grades        100
## 4     ALL BEEF TYPE                  LIVE FOB  Total all grades       3021
## 5            HEIFER         DRESSED DELIVERED    0 - 35% Choice         NA
## 6            HEIFER         DRESSED DELIVERED   35 - 65% Choice         NA
##   weight_range_low weight_range_high weight_range_avg price_range_low
## 1              803              1005              908             220
## 2              984               992              990             222
## 3             1275              1375             1310             140
## 4             1200              1575             1462             138
## 5               NA                NA               NA              NA
## 6               NA                NA               NA              NA
##   price_range_high weighted_avg_price
## 1              226             221.96
## 2              223             222.43
## 3              142             141.50
## 4              142             140.49
## 5               NA                 NA
## 6               NA                 NA
##                                                                          report_title
## 1 5 Area Daily Weighted Average Direct Slaughter Cattle - Negotiated (PDF) (LM_CT100)
## 2 5 Area Daily Weighted Average Direct Slaughter Cattle - Negotiated (PDF) (LM_CT100)
## 3 5 Area Daily Weighted Average Direct Slaughter Cattle - Negotiated (PDF) (LM_CT100)
## 4 5 Area Daily Weighted Average Direct Slaughter Cattle - Negotiated (PDF) (LM_CT100)
## 5 5 Area Daily Weighted Average Direct Slaughter Cattle - Negotiated (PDF) (LM_CT100)
## 6 5 Area Daily Weighted Average Direct Slaughter Cattle - Negotiated (PDF) (LM_CT100)
##   slug_name slug_id   office_name office_code  office_city office_state
## 1  AMS_2466    2466 St Joseph, MO       LS-SJ Saint Joseph           MO
## 2  AMS_2466    2466 St Joseph, MO       LS-SJ Saint Joseph           MO
## 3  AMS_2466    2466 St Joseph, MO       LS-SJ Saint Joseph           MO
## 4  AMS_2466    2466 St Joseph, MO       LS-SJ Saint Joseph           MO
## 5  AMS_2466    2466 St Joseph, MO       LS-SJ Saint Joseph           MO
## 6  AMS_2466    2466 St Joseph, MO       LS-SJ Saint Joseph           MO
##   market_location_name market_location_city market_location_state
## 1       St. Joseph, MO           St. Joseph                    MO
## 2       St. Joseph, MO           St. Joseph                    MO
## 3       St. Joseph, MO           St. Joseph                    MO
## 4       St. Joseph, MO           St. Joseph                    MO
## 5       St. Joseph, MO           St. Joseph                    MO
## 6       St. Joseph, MO           St. Joseph                    MO
##                     market_type          market_type_category
## 1 Direct Livestock - LMR Cattle Direct Livestock - LMR Cattle
## 2 Direct Livestock - LMR Cattle Direct Livestock - LMR Cattle
## 3 Direct Livestock - LMR Cattle Direct Livestock - LMR Cattle
## 4 Direct Livestock - LMR Cattle Direct Livestock - LMR Cattle
## 5 Direct Livestock - LMR Cattle Direct Livestock - LMR Cattle
## 6 Direct Livestock - LMR Cattle Direct Livestock - LMR Cattle
##        published_date
## 1 2021-12-30 10:49:02
## 2 2021-12-30 10:49:02
## 3 2021-12-30 10:49:02
## 4 2021-12-30 10:49:02
## 5 2021-12-30 10:49:02
## 6 2021-12-30 10:49:02

2 Detailが使えそうでした

2.1 グラフ

beef3 <- beef2 %>%
  select(report_date, class_description, weighted_avg_price) %>%
  filter(!is.na(weighted_avg_price))

n <-ggplot(beef3, aes(x = report_date, y = weighted_avg_price)) +
  geom_line() +
  facet_grid(class_description~.) +
  ylim(0, max(beef3$weighted_avg_price))

ggplotly(n)

2.2

beef3$year_month <- format(as.Date(beef3$report_date), "%Y-%m")


milkdata_summary <- beef3 %>%
  group_by(year_month, class_description) %>%
  summarize(平均値 = round(mean(weighted_avg_price),2 ), 標準偏差 = round(sd(weighted_avg_price),2 ), 最大値 = round(max(weighted_avg_price),2 ), 最小値 = round(min(weighted_avg_price),2 ))




milkdata_summary_table <- kable(milkdata_summary, "html") %>%
  kable_classic(full_width = F) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)


milkdata_summary_table
year_month class_description 平均値 標準偏差 最大値 最小値
2021-01 ALL BEEF TYPE 137.08 31.57 176.30 106.21
2021-01 HEIFER 129.40 28.86 177.00 108.54
2021-01 MIXED STEER/HEIFER 134.44 31.03 176.91 105.00
2021-01 STEER 134.65 30.89 176.10 105.00
2021-02 ALL BEEF TYPE 147.47 33.07 182.00 112.69
2021-02 HEIFER 137.41 31.64 181.72 112.58
2021-02 MIXED STEER/HEIFER 143.45 32.85 182.00 110.00
2021-02 STEER 141.73 32.62 182.00 112.00
2021-03 ALL BEEF TYPE 145.08 33.18 185.00 112.00
2021-03 HEIFER 135.79 31.36 185.00 111.63
2021-03 MIXED STEER/HEIFER 142.27 32.87 185.00 112.49
2021-03 STEER 141.21 32.65 185.00 112.89
2021-04 ALL BEEF TYPE 154.44 35.80 195.83 117.32
2021-04 HEIFER 147.30 34.97 196.00 116.59
2021-04 MIXED STEER/HEIFER 154.11 35.77 196.00 117.00
2021-04 STEER 148.67 35.09 196.00 115.77
2021-05 ALL BEEF TYPE 153.11 35.23 192.00 117.00
2021-05 HEIFER 149.29 34.91 192.00 117.87
2021-05 MIXED STEER/HEIFER 152.36 35.26 191.94 117.00
2021-05 STEER 149.71 34.97 195.00 116.21
2021-06 ALL BEEF TYPE 156.56 36.12 200.76 119.83
2021-06 HEIFER 151.04 35.56 200.00 119.00
2021-06 MIXED STEER/HEIFER 154.74 36.12 200.00 118.00
2021-06 STEER 154.55 36.10 201.74 118.00
2021-07 ALL BEEF TYPE 156.64 37.03 201.33 119.93
2021-07 HEIFER 152.02 37.13 202.00 117.00
2021-07 MIXED STEER/HEIFER 151.33 36.36 200.44 116.00
2021-07 STEER 155.80 37.39 202.00 117.00
2021-08 ALL BEEF TYPE 160.57 37.24 206.90 121.93
2021-08 HEIFER 158.32 38.00 207.12 117.78
2021-08 MIXED STEER/HEIFER 157.88 37.69 206.39 119.00
2021-08 STEER 158.64 37.52 207.76 117.50
2021-09 ALL BEEF TYPE 157.24 36.28 203.00 122.00
2021-09 HEIFER 154.63 36.36 203.00 121.98
2021-09 MIXED STEER/HEIFER 156.57 36.53 203.00 122.00
2021-09 STEER 155.82 36.35 203.00 122.00
2021-10 ALL BEEF TYPE 158.58 35.89 200.00 121.89
2021-10 HEIFER 149.84 34.40 200.15 121.65
2021-10 MIXED STEER/HEIFER 154.48 35.62 200.00 121.57
2021-10 STEER 156.16 35.85 200.00 121.95
2021-11 ALL BEEF TYPE 168.38 38.18 220.00 126.00
2021-11 HEIFER 155.20 34.78 217.18 126.00
2021-11 MIXED STEER/HEIFER 163.80 37.34 217.79 126.00
2021-11 STEER 163.09 37.19 220.00 127.92
2021-12 ALL BEEF TYPE 173.51 39.93 222.43 135.05
2021-12 HEIFER 167.69 38.75 222.00 135.00
2021-12 MIXED STEER/HEIFER 170.56 39.37 222.23 135.00
2021-12 STEER 168.01 38.81 222.43 133.50