This is a data wrangling project which aims to provide facts and figures of U.S. Beef industry using relevant R packages.
Packages are employed to clean, modify, arrange, visualize, and map the data with the most widely used functions and techniques in the packages.
You will become familiar with beef industry’s data and figures related to beef cattle inventory, beef production, international cattle and beef trade, cattle and beef prices, and consumption. Database covers the period from 1920 to 2022.
Tables provided in the project are mini databases, and you can search,sort, and filter columns to get data for year, country, state, and county of your interest.
This project aims to provide facts and figures of U.S. beef industry with R data wrangling, visualization and mapping functions and techniques.
#install.packages("...")
#data wrangling
library(tidyverse)
library(dtplyr)
library(tidyfast)
library(data.table)
#plots
library(ggplot2)
library(ggrepel)
library(cowplot)
library(lubridate)
#R interface/JavaScript-DataTables
library(knitr)
library(DT)
#load excel files
library(readxl)
#animated plots
library(png)
library(gifski)
library(gganimate)
#mapping
library(usmap)
#rmarkdown
library(knitr)
#USDA data with API
library(tidyUSDA)
#plot theme settings
= theme(
plot_theme plot.title = element_text(face="bold", size = 20),
axis.title.x = element_text(face="bold", size = 16),
axis.text.x = element_text(face="bold",size = 14),
axis.title.y = element_text(face="bold",size = 16),
axis.text.y = element_text(face="bold",size = 14),
strip.text.x = element_text(size=rel(3.5)),
strip.text.y = element_text(size=rel(3.5)),
legend.title = element_text(face="bold",size=16),
legend.text = element_text(face="bold",size=14),
)
United States is the largest producer and consumer of beef in the world with 20% of the global beef production. [Source]
The main stages of beef-cattle production process in U.S. are cow-calf operations, stocker/backgrounding operations, feedlots, meat packers and processors, and retailers. The production process begins with the cow-calf farms where cows and calves are raised. The next stage of production occurs at stocker/backgrounding operations where calves are placed on grass or other type of roughage. Feedlots are the final chain in the cattle production and they feed cattle with different rations of grain, silage, and/or protein supplements and sell to beef packers and processors where beef and beef by-products are produced and sold to retailers. [Source]
The economic size of beef-cattle industry including direct and indirect economic contributions during on-farm and post-farm activities is estimated as $167 billion in 2016. [Source]
This project presents facts and figures of the industry with 4 main variables: production, international trade, price, and consumption. Production, international trade, and price sections include both cattle and beef sectors’ data. Consumption figures are per capita values and beef is compared with pork and chicken per capita consumption.
USDA National Agricultural Statistics Service database is the data source of the project, unless stated otherwise.
All data used in the project are provided at github repository of the project.
Â
Cattle
Beef cow inventory data is used for cattle production section. National, state and county level data are obtained for years available in the database.
= read_csv("data/beef_cattle_inv_yearly.csv") cattleinv_data_yearly
= read_csv("data/beef_cattle_inv_state_year.csv") cattleinv_data_state_year
= read_csv("data/beef_cattle_inv_county_2021.csv") cattleinv_data_county
Â
Beef
Beef production values are yearly production amounts (million pounds).
= read_excel("data/yearly beef production.xlsx") beef_prod_data
Â
Trade data are the amount (pound or head) of exports and imports between trade partner countries and United States.Â
Cattle
Export
= read_excel("data/cattle_trade.xlsx", sheet = "export") export_data_cattle
Import
= read_excel("data/cattle_trade.xlsx", sheet = "import") import_data_cattle
Â
Beef
Export
= read_excel("data/beef_trade.xlsx", sheet = "export") export_data
Import
= read_excel("data/beef_trade.xlsx", sheet = "import") import_data
Â
Cattle
Cattle prices are monthly ‘prices received’ values for beef cattle, calves, cows and steers and heifers. All prices are dollars per cwt (hundred pounds of weight).
= read_excel("data/feedercattle_prices.xlsx") cattle_price_data
Â
Beef
Beef price data covers monthly farm, wholesale, and retail prices. All prices are in cents per pound.
= read_excel("data/beef_prices.xlsx") beef_price_data
Â
Population
= read_excel("data/yearly beef production.xlsx") beef_prod_data
Â
Consumption
Consumption data is in per capita values.
= read_excel("data/beef_consumption.xls") beef_consmptn_data
Â
Table 1 shows U.S. beef cattle inventory. There were 30.1 million head of beef cows in U.S. as of January 1, 2022.
The number is down 2.3% from 2021. It has been decreasing since 2019.
= as.data.table(cattleinv_data_yearly)
table_data %>%
table_data :=Value/1000]%>%
.[, Value:= (Value/lead(Value) - 1)]%>%
.[, pct_change datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 1: U.S. Beef Cattle Inventory: 1920-2022')
colnames = c('Year', '# of Heads-1000', 'Annual Change'))%>%
), formatCurrency('Value',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('pct_change', 1)
Average beef cattle inventory numbers are;
mean(Value[1:10])][] table_data[,
[1] 30471.86
mean(Value[1:20])][] table_data[,
[1] 31255.85
mean(Value[1:30])][] table_data[,
[1] 32193.13
Â
The maximum value was 45.7 million on January 1, 1975 and the lowest number was 8.9 million on January 1, 1928 (Sort and Search options can be used to filter table and sort data.).Â
Â
As we see from Figure 1, beef cattle inventory has a decreasing trend since 1975 [Source: An Article by Dr. Kenny Burdine (University of Kentucky) ]. 10, 20, and 30 years average values are relatively stable.
:= (Value/lead(Value) - 1)*100]
table_data[,pct_change = as.data.frame(table_data)
table_data
= ggplot(table_data, aes(x = Year, y = Value)) +
g1 labs(title = "Figure 1-a) U.S. Beef Cattle Inventory-1000 heads") +
geom_line(color="orange") +
theme_bw()+
+
plot_themeannotate(
geom = "curve", x = 1965, y = 43500, xend = 1975, yend = 45500,
curvature = -.3, arrow = arrow(length = unit(3, "mm")) )+
annotate("text", y = 43000, x = 1950, label = "max: ~45.7 milion in 1975", size =5, angle = 0, color = "red")
= ggplot(table_data, aes(x = Year, y = `pct_change`)) +
g2 labs(title = "Figure 1-b) U.S. Beef Cattle Inventory-% change") +
geom_line(color="orange") +
theme_bw()+
plot_theme
plot_grid(g1, g2)
Â
Table 2 provides inventory data for 50 states.
You can check for each state’s inventory number by filtering and sorting data.
= as.data.table(cattleinv_data_state_year)
table_data %>%
table_data order(-Year)]%>%
.[:=Value/1000]%>%
.[, Valuec("Year", "State","Value")] %>%
.[, datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 2: U.S. Beef Cattle Inventory by State: 1920-2022')
colnames = c('Year', 'State', 'Value-1000 heads'))%>%
), formatCurrency('Value',currency = "", interval = 3, mark = ",", digits=0)
The output of below code chunk tells that Texas has been the state with the highest beef cattle inventory since 1919.
= as.data.table(cattleinv_data_state_year)
table_data = table_data %>%
table_data c("Year", "State", "Value")] %>%
.[, order(-Value)]%>%
.[:=Value/1000]%>%
.[, Value==2022] %>%
.[Year:= (Value*100/sum(Value))]%>%
.[, state_share c("Year","State","Value", "state_share")]
.[,
distinct(table_data[table_data[, .I[Value == max(Value)], by=Year]$V1], State)
Source: local data table [1 x 1]
Call: unique(`_DT1`[, .(State)])
State
<chr>
1 TEXAS
# Use as.data.table()/as.data.frame()/as_tibble() to access results
Â
Â
On January 1, 2022, Texas had 4.48 million beef cows. Its share was 14.9%.
The other states with the highest number of beef cows are Oklahoma, Missouri, Nebraska, and South Dakota.
Seven states have more than 1 million beef cows in 2022 with a total share of 48.83%.
sum(state_share[1:7])][] table_data[,
[1] 48.82971
Â
Â
%>%
table_data c("State", "Value", "state_share")] %>%
.[, := state_share/100]%>%
.[, state_share datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 3: U.S. Beef Cattle Inventory by State: 2022')
colnames = c('State', '# of Heads-1000', 'State Share'))%>%
), formatCurrency('Value',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('state_share', 1)
Figure 2 provides a map of U.S. states with their beef cow inventory on January 1, 2022.
=table_data %>%
state_map_data c("State", "Value")] %>%
.[, order(-Value)]
.[
setnames(state_map_data,"State","state")
=
g1 plot_usmap(data = state_map_data, values = "Value", labels = TRUE, color = "black") +
scale_fill_continuous(name = "Beef Cattle Inventory", low = "white", high = "red", label = scales::comma) +
labs(title = "Figure 2: U.S. Beef Cattle Inventory by State, 2022-1000 heads") +
theme(plot.title = element_text(face="bold",size=20), legend.position = "right",
legend.title = element_text(face="bold",size=15), legend.text = element_text(size=12))
# Set label font size
$layers[[2]]$aes_params$size =5
g1
g1
Figure 3 is an animated map of U.S. states that shows the change between 1972-2022.
= as.data.table(cattleinv_data_state_year)
table_data = table_data %>%
animated_map_data c("Year", "State", "Value")] %>%
.[, :=Value/1000]%>%
.[, Value> 1972]
.[Year
setnames(animated_map_data, "State", "state")
=
plot plot_usmap(data = animated_map_data, values = "Value", labels = FALSE) +
scale_fill_continuous(name = "Beef Cattle Inventory", low = "white", high = "purple", label = scales::comma) +
labs(title = "Figure 3: Kentucky Beef Cattle Inventory by State 1972-2022", subtitle = 'Year: {closest_state}')+
theme(plot.title = element_text(face="bold",size=20), legend.position = "right", plot.subtitle = element_text(face="bold",size=16),
legend.title = element_text(face="bold",size=15), legend.text = element_text(size=12))+
transition_states(Year)
animate(plot, fps = 5)
Â
Table 4 presents beef inventory across counties on January 1, 2021.
Holt County in Nebraska has the highest number of beef cows.
It is followed by Okeechobee-Florida, Lincoln-Nebraska, Meade-South Dakota, and Fergus-Montana.
You are welcomed to search your county’s rank and numbers using Search filter.
= as.data.table(cattleinv_data_county)
table_data %>%
table_data order(-Value)] %>%
.[c("State", "County","Value")] %>%
.[, := (Value/sum(Value, na.rm=TRUE))]%>%
.[, county_share c("State", "County","Value", "county_share")] %>%
.[, datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 4: U.S. Beef Cattle Inventory by County- January 1, 2021')
colnames = c('State','County','# of Heads', 'County Share'))%>%
), formatCurrency('Value',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('county_share', 2)
Â
Â
Â
Kentucky had about 966 thousand heads of beef cattle. The number is 0.7% less than 2021.
It is still the largest cattle producing state east of the Mississippi River.
= as.data.table(cattleinv_data_state_year)
table_data %>%
table_data c("Year", "State", "Value")] %>%
.[, :=Value/1000]%>%
.[, Value=="KENTUCKY"] %>%
.[Statec("Year","Value")] %>%
.[, := (Value/lead(Value) - 1)]%>%
.[, pct_change datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 3: Kentucky Beef Cattle Inventory by State: 1920-2022')
colnames = c('Year', '# of Heads-1000', 'Annual Change'))%>%
), formatCurrency('Value',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('pct_change', 1)
Â
Â
There are 33,823 beef cattle producers in the state and average herd size is about 31 head each. [Source]
The Lowe Family from Warren county has been farming in Kentucky for 219 years. Please visit the link for the details of the family’s operation.
Similar to national beef inventory values across years, Kentucky beef inventory has also been decreasing since 1975 when it has the highest number (1.43 million).
Figure 4 shows the trend and annual changes.
= table_data %>%
table_data :=Value/1000]%>%
.[, Value=="KENTUCKY"] %>%
.[Statec("Year","Value")]
.[,
:= (Value/lead(Value) - 1)*100]
table_data[, pct_change = as.data.frame(table_data)
table_data
= ggplot(table_data, aes(x = Year, y = Value)) +
g1 labs(title = "Figure 4: a) Kentucky Cattle Inventory-1000 heads") +
geom_line(color="orange") +
theme_bw()+
+
plot_themeannotate(
geom = "curve", x = 1966, y = 1355, xend = 1975, yend = 1429,
curvature = -.3, arrow = arrow(length = unit(3, "mm")) )+
annotate("text", y = 1350, x = 1955, label = "max: ~1.5 milion in 1975", size =5, angle = 0)
= ggplot(table_data, aes(x = Year, y = `pct_change`)) +
g2 labs(title = "Figure 4:b) Kentucky Beef Cattle Inventory-% change") +
geom_line(color="orange") +
theme_bw()+
plot_theme
plot_grid(g1, g2)
Â
County Level
Top beef cattle counties in Kentucky are Barren, Pulaski, Madison, Breckinridge, and Warren (Table 5).
= as.data.table(cattleinv_data_county)
table_data %>%
table_data order(-Value)] %>%
.[=="KENTUCKY"] %>%
.[Statec("County","Value")] %>%
.[, datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 5: Kentucky Beef Cattle Inventory by County- January 1, 2021')
colnames = c('County','# of Heads'))%>%
), formatCurrency('Value',currency = "", interval = 3, mark = ",", digits = 0)
Figure 5 provides a map of Kentucky counties with their beef cow inventory on January 1, 2021.
= table_data %>%
ky_data order(-Value)] %>%
.[=="KENTUCKY"] %>%
.[Statec("County","Value")]
.[,
setnames(ky_data,"County","county")
= read_csv("data/fips_ky.csv")
ky_fips = merge(ky_data,ky_fips)
ky_data_plot
=
g1 plot_usmap(data = ky_data_plot, values = "Value", regions="county",
include = c("KY"), labels = TRUE, color = "black") +
scale_fill_continuous(name = "Beef Cattle Inventory",
low = "white", high = "cornflowerblue", label = scales::comma) +
labs(title = "Figure 5: Kentucky Beef Cattle Inventory by County, 2021-heads") +
theme(plot.title = element_text(face="bold",size=20), legend.position = "right",
legend.title = element_text(face="bold",size=15), legend.text = element_text(size=12))
# Set label font size
$layers[[2]]$aes_params$size =3
g1
g1
The total beef production was 28 billion pounds in 2021, 2.8% higher than 27.2 billion pounds in the previous year.
This number is the maximum amount of the beef production in U.S. for the period 1970-2021.
Â
Â
= as.data.table(beef_prod_data[, -c(3:10), with=FALSE])
table_data %>%
table_data order(-year)]%>%
.[:= (production/lead(production) - 1)]%>%
.[, pct_change datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 6: U.S. Beef Production: 1970-2021')
colnames = c('Year', 'Million pounds', 'Annual Change'))%>%
), formatCurrency('production',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('pct_change', 1)
Average beef production values are;
mean(production[42:52])][] table_data[,
[1] 26097.9
mean(production[32:52])][] table_data[,
[1] 26101.79
mean(production[22:52])][] table_data[,
[1] 25708.23
Â
Averages and Figure 6 state that beef production has been stable with a slight fluctuation over the last 30 years.
=table_data[order(-year)]
table_data := (production/lead(production) - 1)*100]
table_data[, pct_change
= ggplot(table_data, aes(x=year,y =production)) +
g1 labs(title ="Figure 6: a) U.S. Beef Production-Million pounds")+
geom_line(color="orange")+
theme_bw()+
plot_theme
= ggplot(table_data, aes(x=year, y=pct_change))+
g2 labs(title ="Figure 6:b) U.S. Beef Production-% Annual Change")+
geom_line(color="orange")+
theme_bw()+
plot_theme
plot_grid(g1, g2)
Â
Canada and Mexico are the largest trading partner countries of U.S. in cattle and beef trade because of regional proximity and the North American Free Trade Agreement-NAFTA. Please see [the article] for the details.
Â
U.S. exported 510 thousand cattle in 2021, almost 60% higher than 2020 (Table 7).
= melt(export_data_cattle, id.vars ="country",
export_data_cattle variable.name = "year", value.name = "export")
= as.data.table(export_data_cattle, key="country")
export_data_cattle :=export/1000] export_data_cattle[, export
= as.data.table(export_data_cattle)
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "export")] %>%
.[, := (export/lead(export) - 1)]%>%
.[, pct_change datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 7: U.S. Cattle Exports: 1989-2021')
colnames = c('Year', 'Export-1000 heads', 'Annual Change'))%>%
), formatCurrency('export',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('pct_change', 1)
Â
Average cattle export values are;
= as.data.table(export_data_cattle)
table_data = table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "export")]
.[,
mean(export[1:10])][] table_data[,
[1] 217.4851
mean(export[1:20])][] table_data[,
[1] 156.0983
mean(export[1:33])][] table_data[,
[1] 197.7053
= as.data.table(export_data_cattle)
table_data =
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[:= (export/lead(export) - 1)*100]%>%
.[, pct_change c("year", "export", "pct_change")]
.[,
:= as.numeric(as.character(year))]
table_data[, year
= ggplot(table_data, aes(x=year, y = export)) +
g1 labs(title ="Figure 7: a) U.S. Cattle Export-1989-2021")+
geom_line(color="orange")+
theme_bw()+
plot_theme
= ggplot(table_data, aes(x=year, y=pct_change))+
g2 labs(title ="Figure 7: b) U.S. Cattle Export-1989-2021, % Annual Change")+
geom_line(color="orange")+
theme_bw()+
plot_theme
plot_grid(g1, g2)
Â
U.S. cattle exports have been highly volatile over the data period (Averages and Figure 7).
Â
By Countries
U.S. exported cattle to 34 countries in 2021.
= as.data.table(export_data_cattle)
table_data is.na(table_data)] = 0
table_data[= table_data %>%
table_data c("country", "year", "export")] %>%
.[, !="Total"]%>%
.[country ==2021]
.[year
distinct(table_data[table_data[, .I[export != 0], by=year]$V1], country)
Source: local data table [34 x 1]
Call: unique(`_DT2`[, .(country)])
country
<chr>
1 Bangladesh
2 Bermuda
3 Brazil
4 Canada
5 Colombia
6 Curaçao
# ... with 28 more rows
# Use as.data.table()/as.data.frame()/as_tibble() to access results
count(distinct(table_data[table_data[, .I[export != 0], by=year]$V1], country))
Source: local data table [1 x 1]
Call: unique(`_DT3`[, .(country)])[, .(n = .N)]
n
<int>
1 34
# Use as.data.table()/as.data.frame()/as_tibble() to access results
Â
Of these countries, Canada’s share was 77.1% and Mexico’s share was 18.1% (Table 9 and Figure 8). Their combined share is 95.2%.
= export_data_cattle[year =="2021"]
cattle_exports setorderv(cattle_exports, cols="export", order=-1L, na.last=TRUE)
= cattle_exports[2:111]
data= data[, c("year"):=NULL]
data
:=round(export*100/509.576, digits = 1)]
data[, exportsetnames(data, "export", "export_share")
= sum(data$export[6:111], na.rm = T)
rest_total <- data.frame("restoftheworld", rest_total)
rest_totw names(rest_totw) = c("country", "export_share")
= data[1:5]
data
= rbind(data, rest_totw)
data1
= setorderv(data1, cols="export_share", order=-1L, na.last=TRUE)
table_data
::kable(
knitr1:6],
table_data[col.names = c('Country', 'Share-%'),
align = "lccrr",
caption = "Table 8: U.S. Cattle Exports by Country"
)
Country | Share-% |
---|---|
Canada | 77.1 |
Mexico | 18.1 |
Pakistan | 1.8 |
Vietnam | 1.4 |
Turkey | 0.8 |
restoftheworld | 0.6 |
#labels
<- data1 %>%
data2 mutate(csum = rev(cumsum(rev(export_share))),
pos = export_share/2 + lead(csum, 1),
pos = if_else(is.na(pos), export_share/2, pos))
= as.data.frame(data2)
data2 ggplot(data1, aes(x = "" , y = export_share, fill=fct_inorder(country))) +
labs(title = "Figure 8: U.S. Cattle Exports by Country")+
geom_col(width = 1, color = 1) +
coord_polar(theta = "y") +
scale_fill_brewer(palette = "Pastel1") +
geom_label_repel(data = data2,
aes(y = pos, label = paste0(export_share, "%")),
size = 4.5, nudge_x = 1, show.legend = FALSE) +
guides(fill = guide_legend(title = "Country")) +
theme_bw()+
plot_theme
Â
U.S. imported 1,775 thousand cattle in 2021, 16% lower than 2020 (Table 9).
= melt(import_data_cattle, id.vars ="country",
import_data_cattle variable.name = "year", value.name = "import")
= as.data.table(import_data_cattle, key = "country")
import_data_cattle
:=import/1000] import_data_cattle[, import
= as.data.table(import_data_cattle)
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "import")] %>%
.[, := (import/lead(import) - 1)]%>%
.[, pct_change datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 9: U.S. Cattle Imports: 1989-2021')
colnames = c('Year', 'Import-1000 heads', 'Annual Change'))%>%
), formatCurrency('import',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('pct_change', 1)
Â
Average cattle import values are;
= as.data.table(import_data_cattle)
table_data = table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "import")]
.[,
mean(import[1:10])][] table_data[,
[1] 2000.449
mean(import[1:20])][] table_data[,
[1] 2045.319
mean(import[1:33])][] table_data[,
[1] 2081.145
= as.data.table(import_data_cattle)
table_data =
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[:= (import/lead(import) - 1)*100]%>%
.[, pct_change c("year", "import", "pct_change")]
.[,
:= as.numeric(as.character(year))]
table_data[, year
= ggplot(table_data, aes(x=year, y = import)) +
g1 labs(title ="Figure 9: a) U.S. Cattle Import-1989-2021")+
geom_line(color="orange")+
theme_bw()+
plot_theme
= ggplot(table_data, aes(x=year, y=pct_change))+
g2 labs(title ="Figure 9: b) U.S. Cattle Import-1989-2021, % Annual Change")+
geom_line(color="orange")+
theme_bw()+
plot_theme
plot_grid(g1, g2)
Â
U.S. cattle import are more stable comparing to exports over the data period (Averages and Figure 9).
Â
By Countries
U.S. imported cattle from 2 countries in 2021: Canada and Mexico.
= as.data.table(import_data_cattle)
table_data is.na(table_data)] = 0
table_data[= table_data %>%
table_data c("country", "year", "import")] %>%
.[, !="Total"]%>%
.[country ==2021]
.[year
distinct(table_data[table_data[, .I[import != 0], by=year]$V1], country)
Source: local data table [2 x 1]
Call: unique(`_DT5`[, .(country)])
country
<chr>
1 Canada
2 Mexico
# Use as.data.table()/as.data.frame()/as_tibble() to access results
count(distinct(table_data[table_data[, .I[import != 0], by=year]$V1], country))
Source: local data table [1 x 1]
Call: unique(`_DT6`[, .(country)])[, .(n = .N)]
n
<int>
1 2
# Use as.data.table()/as.data.frame()/as_tibble() to access results
Â
Canada’s share was 63.6% and Mexico’s share was 36.4% (Table 10 and Figure 10).
= import_data_cattle[year =="2021" ]
cattle_imports setorderv(cattle_imports, cols="import", order=-1L, na.last=TRUE)
= cattle_imports[2:24]
data= data[, c("year"):=NULL]
data
:=round(import*100/1775.492, digits = 1)]
data[, importsetnames(data, "import", "import_share")
= sum(data$import[3:24], na.rm = T)
rest_total <- data.frame("restoftheworld", rest_total)
rest_totw names(rest_totw) = c("country", "import_share")
= data[1:2]
data
= rbind(data, rest_totw)
data1 = setorderv(data1, cols="import_share", order=-1L, na.last=TRUE)
table_data ::kable(
knitr1:3],
table_data[col.names = c('Country', 'Share-%'),
align = "lccrr",
caption = "Table 10: U.S. Cattle Imports by Country"
)
Country | Share-% |
---|---|
Mexico | 63.6 |
Canada | 36.4 |
restoftheworld | 0.0 |
#labels
<- data1 %>%
data2 mutate(csum = rev(cumsum(rev(import_share))),
pos = import_share/2 + lead(csum, 1),
pos = if_else(is.na(pos), import_share/2, pos))
= as.data.frame(data2)
data2 ggplot(data1, aes(x = "" , y = import_share, fill=fct_inorder(country))) +
labs(title = "Figure 10: U.S. Cattle Imports by Country")+
geom_col(width = 1, color = 1) +
coord_polar(theta = "y") +
scale_fill_brewer(palette = "Pastel1") +
geom_label_repel(data = data2,
aes(y = pos, label = paste0(import_share, "%")),
size = 4.5, nudge_x = 1, show.legend = FALSE) +
guides(fill = guide_legend(title = "Country")) +
theme_bw()+
plot_theme
Â
Table 11 provides U.S. trade position in cattle trade for 1989-2021.
= merge( export_data_cattle,import_data_cattle, by = c("country", "year"), all=T)
cattle_trade_data = cattle_trade_data[, trade_balance:= export-import]
cattle_trade_data = cattle_trade_data[, us_status:= ifelse(trade_balance<0, "net_importer", "net_exporter")]
cattle_trade_data = cattle_trade_data[country=="Total"]
total_cattle_trade setorder(total_cattle_trade, cols = -"year")
= as.data.table(total_cattle_trade)
table_data %>%
table_data := NULL]%>%
.[, country:=round(trade_balance, digits = 0)]%>%
.[, trade_balancedatatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 11: U.S. Cattle Trade-1000 heads')
colnames = c('Year', 'Export', 'Import', 'Balance', 'Position'))%>%
), formatCurrency(c('export','import', 'trade_balance'), currency = "", interval = 3, mark = ",", digits=0)
Â
U.S. was net importer in cattle trade during the period 1989-2021 (Figure 11).
is.na(table_data)] = 0
table_data[%>%
table_data := NULL]%>%
.[, country:=round(trade_balance, digits = 0)]
.[, trade_balance
=.(us_status )][] table_data[, .N, by
us_status N
1: net_importer 33
= table_data %>%
dt := NULL]%>%
.[, country:=round(trade_balance, digits = 0)]
.[, trade_balance
:= as.numeric(as.character(year))]
dt[, year
=
dt as.data.frame(dt) %>%
select(year, import, export, trade_balance) %>%
gather(key = "variable", value = "value", -year)
ggplot(dt, aes(x = year, y = value)) +
labs(title = "Figure 11: U.S. Cattle Trade 1989-2021") +
geom_line(aes(color = variable), size = 1) +
scale_color_manual(values = c("orange", "lightblue", "red")) +
theme_bw()+
+
plot_themegeom_hline(yintercept=0, linetype="dashed",
color = "black", size=2)
Â
By Countries
Table 12 provides trade position for all countries. You can search countries and sort and/or filter by year to see U.S. trade with other countries.
= merge( export_data_cattle,import_data_cattle, by = c("country", "year"), all=T)
cattle_trade_data
is.na(cattle_trade_data)] = 0
cattle_trade_data[
= cattle_trade_data[, trade_balance:= export-import]
cattle_trade_data
= as.data.frame(cattle_trade_data) %>%
cattle_trade_data mutate(group = case_when(trade_balance<0 ~ "net_importer",
==0 ~ "balanced",
trade_balance>0 ~"net_exporter" ))
trade_balance
= as.data.table(cattle_trade_data)
table_data %>%
table_data :=round(trade_balance, digits = 0)]%>%
.[, trade_balancedatatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 12: U.S. Cattle Trade by Country')
colnames = c('Country','Year', 'Export', 'Import', 'Balance', 'Position'))%>%
), formatCurrency(c('export','import', 'trade_balance'), currency = "", interval = 3, mark = ",", digits=0)
Â
U.S. exported 3,447 thousand pounds in 2021, 16.8% higher than 2020 (Table 13).
= melt(export_data, id.vars ="country",
export_data variable.name = "year", value.name = "export")
= as.data.table(export_data, key="country")
export_data := export/1000] export_data[, export
= as.data.table(export_data)
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "export")] %>%
.[, := (export/lead(export) - 1)]%>%
.[, pct_change datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 13: U.S. Beef Exports: 1989-2021')
colnames = c('Year', 'Export-1000 lbs', 'Annual Change'))%>%
), formatCurrency('export',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('pct_change', 1)
Â
Average beef export values are;
= as.data.table(export_data)
table_data = table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "export")]
.[,
mean(export[1:10])][] table_data[,
[1] 2788.233
mean(export[1:20])][] table_data[,
[1] 2280.016
mean(export[1:33])][] table_data[,
[1] 2069.532
= as.data.table(export_data)
table_data =
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[:= (export/lead(export) - 1)*100]%>%
.[, pct_change c("year", "export", "pct_change")]
.[,
:= as.numeric(as.character(year))]
table_data[, year
= ggplot(table_data, aes(x=year, y = export)) +
g1 labs(title ="Figure 12: a) U.S. Beef Export-1989-2021")+
geom_line(color="orange")+
theme_bw()+
+
plot_themegeom_rect(aes(xmin = 2003, xmax = 2011, ymin = 400 , ymax =2600),
fill = "transparent", color = "black", size = 1, linetype="dashed")+
annotate("text", y =2000, x = 2006, label = "BSE Bans", size =4, color = "red", angle = 0)
= ggplot(table_data, aes(x=year, y=pct_change))+
g2 labs(title ="Figure 12: b) U.S. Beef Export-1989-2021, % Annual Change")+
geom_line(color="orange")+
theme_bw()+
+
plot_themegeom_rect(aes(xmin = 2003, xmax = 2011, ymin = -81 , ymax =65),
fill = "transparent", color = "black", size = 1, linetype="dashed")
plot_grid(g1, g2)
U.S. beef exports have been stable between 1989-2021 except for the period 2004-2011 where we see annual change values of -81.7%(2004) and 64%(2006) (Averages and Figure 12).
Bovine Spongiform Encephalopathy (BSE) is the reason for the decline in 2004 (81.7%). 53 countries banned imports of U.S. beef and beef products. Please see [the article in the link] for details.
Â
By Countries
U.S. exported beef to 126 countries in 2021.
= as.data.table(export_data)
table_data is.na(table_data)] = 0
table_data[= table_data %>%
table_data c("country", "year", "export")] %>%
.[, !="Total"]%>%
.[country ==2021]
.[year
distinct(table_data[table_data[, .I[export != 0], by=year]$V1], country)
Source: local data table [126 x 1]
Call: unique(`_DT8`[, .(country)])
country
<chr>
1 Afghanistan
2 Angola
3 Anguilla
4 Antigua & Barbuda
5 Argentina
6 Aruba
# ... with 120 more rows
# Use as.data.table()/as.data.frame()/as_tibble() to access results
count(distinct(table_data[table_data[, .I[export != 0], by=year]$V1], country))
Source: local data table [1 x 1]
Call: unique(`_DT9`[, .(country)])[, .(n = .N)]
n
<int>
1 126
# Use as.data.table()/as.data.frame()/as_tibble() to access results
Â
Of these countries, Japan’s share was 24%, South Korea’s share was 22.8%, and China’s share was 15.7% (Table 14 and Figure 13). Their combined share is 62.5%.
= export_data[year =="2021"]
beef_exports setorderv(beef_exports, cols="export", order=-1L, na.last=TRUE)
= beef_exports[2:217]
data= data[, c("year"):=NULL]
data
:=round(export*100/3447.0693 , digits = 1)]
data[, exportsetnames(data, "export", "export_share")
= sum(data$export[11:217], na.rm = T)
rest_total <- data.frame("restoftheworld", rest_total)
rest_totw names(rest_totw) = c("country", "export_share")
= data[1:10]
data
= rbind(data, rest_totw)
data1 = setorderv(data1, cols="export_share", order=-1L, na.last=TRUE)
table_data ::kable(
knitr1:11],
table_data[col.names = c('Country', 'Share-%'),
align = "lccrr",
caption = "Table 14:U.S. Beef Exports by Country"
)
Country | Share-% |
---|---|
Japan | 24.0 |
South Korea | 22.8 |
China | 15.7 |
Mexico | 9.2 |
Canada | 8.1 |
restoftheworld | 7.4 |
Taiwan | 5.7 |
Hong Kong | 3.6 |
Indonesia | 1.3 |
Philippines | 1.0 |
Netherlands | 0.8 |
#labels
<- data1 %>%
data2 mutate(csum = rev(cumsum(rev(export_share))),
pos = export_share/2 + lead(csum, 1),
pos = if_else(is.na(pos), export_share/2, pos))
= as.data.frame(data2)
data2 ggplot(data1, aes(x = "" , y = export_share, fill=fct_inorder(country))) +
labs(title = "Figure 13: U.S. Beef Exports Country Shares")+
geom_col(width = 1, color = 1) +
coord_polar(theta = "y") +
scale_fill_brewer(palette = "Pastel1") +
geom_label_repel(data = data2,
aes(y = pos, label = paste0(export_share, "%")),
size = 4.5, nudge_x = 1, show.legend = FALSE) +
guides(fill = guide_legend(title = "Country")) +
theme_bw()+
plot_theme
Â
Figure 14 is the map of top 10 markets for U.S. beef exports in 2021. [A helpful blog for complete global map tutorial]
= data[1:10]
global_map_data$Rank = rank(-global_map_data$export_share)
global_map_dataas.factor(global_map_data$country) %>% levels()
[1] "Canada" "China" "Hong Kong" "Indonesia" "Japan"
[6] "Mexico" "Netherlands" "Philippines" "South Korea" "Taiwan"
= map_data("world")
map_world
= left_join(map_world, global_map_data, by = c('region' = 'country'))
joined_data
<- joined_data %>% mutate(fill_flg = ifelse(is.na(Rank),F,T))
joined_data
ggplot() +
geom_polygon(data = joined_data, aes(x = long, y = lat, group = group, fill = fill_flg)) +
scale_fill_manual(values = c("white","orange")) +
geom_point(data = joined_data, aes(x = long, y = lat), color = "black", size=0.25) +
labs(title = 'Figure 14:Top 10 Markets for U.S. Beef Exports-2021') +
theme(text = element_text(family = "Gill Sans", color = "#FFFFFF")
panel.background = element_rect(fill = "lightblue")
,plot.background = element_rect(fill = "#444444")
,panel.grid = element_blank()
,plot.title = element_text(size = 20)
,plot.subtitle = element_text(size = 10)
,axis.text = element_blank()
,axis.title = element_blank()
,axis.ticks = element_blank()
,legend.position = "none"
, )
Â
U.S. imported 3,348 thousand pounds beef in 2021, 0.2% higher than 2020 (Table 15).
= melt(import_data, id.vars ="country",
import_data variable.name = "year", value.name = "import")
= as.data.table(import_data, key = "country")
import_data :=import/1000] import_data[, import
= as.data.table(import_data)
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "import")] %>%
.[, := (import/lead(import) - 1)]%>%
.[, pct_change datatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 15: U.S. Beef Imports: 1989-2021')
colnames = c('Year', 'Import-1000 lbs', 'Annual Change'))%>%
), formatCurrency('import',currency = "", interval = 3, mark = ",", digits = 0)%>%
formatPercentage('pct_change', 1)
Â
Average beef import values are;
= as.data.table(import_data)
table_data = table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[c("year", "import")]
.[,
mean(import[1:10])][] table_data[,
[1] 2953.42
mean(import[1:20])][] table_data[,
[1] 2934.552
mean(import[1:33])][] table_data[,
[1] 2760.02
= as.data.table(import_data)
table_data =
table_data %>%
table_data =="Total"] %>%
.[countryorder(-year)]%>%
.[:= (import/lead(import) - 1)*100]%>%
.[, pct_change c("year", "import", "pct_change")]
.[,
:= as.numeric(as.character(year))]
table_data[, year
= ggplot(table_data, aes(x=year, y = import)) +
g1 labs(title ="Figure 15: a) U.S. Beef Import-1989-2021")+
geom_line(color="orange")+
theme_bw()+
plot_theme
= ggplot(table_data, aes(x=year, y=pct_change))+
g2 labs(title ="Figure 15: b) U.S. Beef Import-1989-2021, % Annual Change")+
geom_line(color="orange")+
theme_bw()+
plot_theme
plot_grid(g1, g2)
Â
Although 10-20-33 years average values are close to each other, U.S. beef imports have been more volatile comparing to exports during the period (Figure 14).
Â
By Countries
U.S. imported beef from 22 countries in 2021.
= as.data.table(import_data)
table_data is.na(table_data)] = 0
table_data[= table_data %>%
table_data c("country", "year", "import")] %>%
.[, !="Total"]%>%
.[country ==2021]
.[year
distinct(table_data[table_data[, .I[import != 0], by=year]$V1], country)
Source: local data table [22 x 1]
Call: unique(`_DT11`[, .(country)])
country
<chr>
1 Argentina
2 Australia
3 Brazil
4 Canada
5 Chile
6 Costa Rica
# ... with 16 more rows
# Use as.data.table()/as.data.frame()/as_tibble() to access results
count(distinct(table_data[table_data[, .I[import != 0], by=year]$V1], country))
Source: local data table [1 x 1]
Call: unique(`_DT12`[, .(country)])[, .(n = .N)]
n
<int>
1 22
# Use as.data.table()/as.data.frame()/as_tibble() to access results
Â
Of these countries, Canada’s share was 28.1%, Mexico’s share was 20.2%, and New Zealand’s share was 15.0% (Table 16 and Figure 15). Their combined share is 63.3%.
= import_data[year =="2021"]
beef_imports setorderv(beef_imports, cols="import", order=-1L, na.last=TRUE)
= beef_imports[2:94]
data= data[, c("year"):=NULL]
data
:=round(import*100/3347.51555 , digits = 1)]
data[, importsetnames(data, "import", "import_share")
= sum(data$import[11:217], na.rm = T)
rest_total <- data.frame("restoftheworld", rest_total)
rest_totw names(rest_totw) = c("country", "import_share")
= data[1:10]
data= rbind(data, rest_totw)
data1
= setorderv(data1, cols="import_share", order=-1L, na.last=TRUE)
table_data ::kable(
knitr1:11],
table_data[col.names = c('Country', 'Share-%'),
align = "lccrr",
caption = "Table 16: U.S. Beef Imports by Country"
)
Country | Share-% |
---|---|
Canada | 28.1 |
Mexico | 20.2 |
New Zealand | 15.0 |
Australia | 12.3 |
Brazil | 11.0 |
Nicaragua | 5.8 |
Uruguay | 4.0 |
Argentina | 1.9 |
Costa Rica | 0.7 |
Ireland | 0.6 |
restoftheworld | 0.4 |
#labels
<- data1 %>%
data2 mutate(csum = rev(cumsum(rev(import_share))),
pos = import_share/2 + lead(csum, 1),
pos = if_else(is.na(pos), import_share/2, pos))
= as.data.frame(data2)
data2 ggplot(data1, aes(x = "" , y = import_share, fill=fct_inorder(country))) +
labs(title = "Figure 16: U.S. Beef Imports Country Shares")+
geom_col(width = 1, color = 1) +
coord_polar(theta = "y") +
scale_fill_brewer(palette = "Pastel1") +
geom_label_repel(data = data2,
aes(y = pos, label = paste0(import_share, "%")),
size = 4.5, nudge_x = 1, show.legend = FALSE) +
guides(fill = guide_legend(title = "Country")) +
theme_bw()+
plot_theme
Â
Figure 17 is the map of top 10 markets for U.S. beef imports in 2021.
= data[1:10]
global_map_data$Rank = rank(-global_map_data$import_share)
global_map_dataas.factor(global_map_data$country) %>% levels()
[1] "Argentina" "Australia" "Brazil" "Canada" "Costa Rica"
[6] "Ireland" "Mexico" "New Zealand" "Nicaragua" "Uruguay"
= map_data("world")
map_world
= left_join(map_world, global_map_data, by = c('region' = 'country'))
joined_data
<- joined_data %>% mutate(fill_flg = ifelse(is.na(Rank),F,T))
joined_data
ggplot() +
geom_polygon(data = joined_data, aes(x = long, y = lat, group = group, fill = fill_flg)) +
scale_fill_manual(values = c("white","purple")) +
geom_point(data = joined_data, aes(x = long, y = lat), color = "black", size=0.25) +
labs(title = 'Figure 17:Top 10 Markets for U.S. Beef Imports-2021') +
theme(text = element_text(family = "Gill Sans", color = "#FFFFFF")
panel.background = element_rect(fill = "lightblue")
,plot.background = element_rect(fill = "#444444")
,panel.grid = element_blank()
,plot.title = element_text(size = 20)
,plot.subtitle = element_text(size = 10)
,axis.text = element_blank()
,axis.title = element_blank()
,axis.ticks = element_blank()
,legend.position = "none"
, )
Â
Table 17 provides U.S. trade position in beef trade for 1970-2021.
= as.data.table(beef_prod_data[, c(1,4,6)])
beef_trade_data = beef_trade_data[, trade_balance:= export-import]
beef_trade_data = beef_trade_data[, us_status:= ifelse(trade_balance<0, "net_importer", "net_exporter")]
beef_trade_data
%>%
beef_trade_data order(-year)]%>%
.[datatable(beef_trade_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 17: U.S. Beef Trade-1000 pounds')
colnames = c('Year', 'Import ', 'Export', 'Balance', 'Position'))%>%
), formatCurrency(c('import','export', 'trade_balance'), currency = "", interval = 3, mark = ",", digits=0)
Â
During the period 1970-2021, U.S. was net importer in beef trade for 46 years and net exporter for 6 years. 2010-2013, 2018, and 2020 are the periods it had a positive trade balance.
=.(us_status )][] beef_trade_data[, .N, by
us_status N
1: net_importer 46
2: net_exporter 6
%>%
beef_trade_data=="net_exporter"] .[us_status
year import export trade_balance us_status
1: 2010 2297.923 2299.607 1.684 net_exporter
2: 2011 2056.525 2785.059 728.534 net_exporter
3: 2012 2219.783 2452.499 232.716 net_exporter
4: 2013 2249.677 2588.378 338.701 net_exporter
5: 2018 2997.939 3159.526 161.587 net_exporter
6: 2021 3347.515 3447.068 99.553 net_exporter
=
dt %>%
beef_trade_data as.data.frame(dt) %>%
select(year, import, export, trade_balance) %>%
gather(key = "variable", value = "value", -year)
ggplot(dt, aes(x = year, y = value)) +
labs(title = "Figure 18: U.S. Beef Trade") +
geom_line(aes(color = variable), size = 1) +
scale_color_manual(values = c("orange", "lightblue", "red")) +
theme_bw()+
+
plot_themegeom_hline(yintercept=0, linetype="dashed",
color = "black", size=2)+
geom_rect(aes(xmin = 2003, xmax = 2010, ymin = -3270 , ymax =3900),
fill = "transparent", color = "black", size = 1, linetype="dashed")+
annotate("text", y =2000, x = 2006, label = "BSE Bans", size =4, color = "red", angle = 0)
Â
By Countries
Table 18 provides trade position for all countries. You can search countries and sort and/or filter by year to see U.S. trade with other countries.
= merge( export_data,import_data, by = c("country", "year"), all=T)
beef_trade_data
is.na(beef_trade_data)] = 0
beef_trade_data[
= beef_trade_data[, trade_balance:= export-import]
beef_trade_data
= as.data.frame(beef_trade_data) %>%
beef_trade_data mutate(group = case_when(trade_balance<0 ~ "net_importer",
==0 ~ "balanced",
trade_balance>0 ~ "net_exporter" ))
trade_balance
= as.data.table(beef_trade_data)
table_data %>%
table_data :=round(trade_balance, digits = 0)]%>%
.[, trade_balancedatatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 18: U.S. Beef Trade')
colnames = c('Country','Year', 'Export', 'Import', 'Balance', 'Position'))%>%
), formatCurrency(c('export','import', 'trade_balance'), currency = "", interval = 3, mark = ",", digits=0)
Â
Table 19 and Figure 19 show live cattle prices and trends in U.S. from 2012 to 2021.
= as.data.table(cattle_price_data)
table_data
%>%
table_data order(-date)]%>%
.[:=as.character(date)] %>%
.[, datedatatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 19: U.S. Cattle Prices, January 2012-December 2021- Dollars per cwt')
colnames = c('Date','Beef Cattle','Calves', 'Cows','Steers/Heifers'))%>%
), formatCurrency(c('all_beef_cattle', 'calves', 'cows', 'steer_and_heifers'),currency = "", interval = 3, mark = ",", digits = 0)
= as.data.table(cattle_price_data)
table_data = table_data %>%
table_data := mean(all_beef_cattle), by = month(date)]%>%
.[, ten_year_average_all := mean(calves), by = month(date)]%>%
.[, ten_year_average_calves := mean(cows), by = month(date)]%>%
.[, ten_year_average_cows := mean(steer_and_heifers), by = month(date)] .[, ten_year_average_steer_and_heifers
=
dt %>%
table_data as.data.frame(dt) %>%
select(date, all_beef_cattle, calves, cows, steer_and_heifers, ten_year_average_all,ten_year_average_calves,ten_year_average_cows,ten_year_average_steer_and_heifers) %>%
gather(key = "price", value = "value", -date)
ggplot(dt, aes(x = date, y = value)) +
labs(title = "Figure 19: U.S. Cattle Prices-Dollars per cwt") +
geom_line(aes(color = price), size = 1) +
scale_color_manual(values = c("orange", "lightblue", "lightgreen", "black", "red", "brown", "gray", "purple" )) +
theme_bw()+
plot_theme
Â
Average prices for 2021 are:
= table_data%>%
table_dataorder(-date)]
.[
mean(all_beef_cattle[1:12])][] table_data[,
[1] 120.8333
mean(calves[1:12])][] table_data[,
[1] 168.6667
mean(cows[1:12])][] table_data[,
[1] 70.13333
mean(steer_and_heifers[1:12])][] table_data[,
[1] 123.6667
Â
Table 20 and Figure 21 presents beef prices data and trends in U.S. from 1970 to 2021.
= as.data.table(beef_price_data[, -c(5:7)])
table_data %>%
table_data order(-date)]%>%
.[:=as.character(date)] %>%
.[, datedatatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 20: U.S. Beef Prices- Cents per pound')
colnames = c('Date', 'Farm','Wholesale','Retail'))%>%
), formatCurrency(c('farm','wholesale','retail'),currency = "", interval = 3, mark = ",", digits = 0)
= as.data.table(beef_price_data[505:624, -c(5:7)])
table_data = table_data %>%
table_data := mean(farm), by = month(date)]%>%
.[, ten_year_average_farm := mean(wholesale), by = month(date)]%>%
.[, ten_year_average_wholesale := mean(retail), by = month(date)] .[, ten_year_average_retail
=
dt %>%
table_data as.data.frame(dt) %>%
select(date, farm, wholesale, retail,ten_year_average_farm,ten_year_average_wholesale,ten_year_average_retail) %>%
gather(key = "price", value = "value", -date)
ggplot(dt, aes(x = date, y = value)) +
labs(title = "Figure 20: U.S. Beef Prices-cents per pound") +
geom_line(aes(color = price), size = 1) +
scale_color_manual(values = c("orange", "lightblue", "lightgreen","black", "red", "brown")) +
theme_bw()+
plot_theme
Â
Average prices in 2021 are:
mean(farm[109:120])][] table_data[,
[1] 266.7043
mean(wholesale[109:120])][] table_data[,
[1] 423.2084
mean(retail[109:120])][] table_data[,
[1] 724.5227
Â
Price spread is calculated as the difference between two prices in the same supply chain.
U.S. beef price spreads are given in Table 21.
= as.data.table(beef_price_data[, -c(2:4)])
table_data %>%
table_data order(-date)]%>%
.[:=as.character(date)] %>%
.[, datedatatable(table_data,caption = htmltools::tags$caption(
style = 'caption-side: top; text-align: center;', ('Table 21: U.S. Beef Price Spreads- Cents per pound')
colnames = c('Date', 'Farm-Retail','Farm-Wholesale','Wholesale-Retail'))%>%
), formatCurrency(c('farm-retail','farm-wholesale','wholesale-retail'),currency = "", interval = 3, mark = ",", digits = 0)
Â
Average price spreads in 2021 are:
= table_data%>%
table_dataorder(-date)]
.[
mean(`farm-retail`[1:12])][] table_data[,
[1] 457.8185
mean(`farm-wholesale`[1:12])][] table_data[,
[1] 156.5041
mean(`wholesale-retail`[1:12])][] table_data[,
[1] 301.3144
= as.data.table(beef_price_data[505:624, c(1,5:7)])
table_data = table_data %>%
table_data := mean(`farm-retail`), by = month(date)]%>%
.[, ten_year_average_farmtoretail := mean(`farm-wholesale`), by = month(date)]%>%
.[, ten_year_average_farmtowholesale := mean(`wholesale-retail`), by = month(date)] .[, ten_year_average_wholesaletoretail
=
dt %>%
table_data as.data.frame(dt) %>%
select(date, `farm-retail`, `farm-wholesale`, `wholesale-retail` ,ten_year_average_farmtoretail,ten_year_average_farmtowholesale,ten_year_average_wholesaletoretail) %>%
gather(key = "price", value = "value", -date)
ggplot(dt, aes(x = date, y = value)) +
labs(title = "Figure 21: U.S. Beef Prices-cents per pound") +
geom_line(aes(color = price), size = 1) +
scale_color_manual(values = c("orange", "lightblue", "lightgreen","black", "red", "brown")) +
theme_bw()+
plot_theme
Â
During the COVID-19 pandemic, we have observed unexpected price movements in the U.S. beef market due to the disruptions in the beef marketing channel.
All cattle prices declined during the pandemic (Figure 22). We can observe that farm level beef prices also decreased during the pandemic. On the other hand, wholesale and retail level beef prices had price hikes during the pandemic (Figure 23).
Please see the article in the link for a detailed discussion of the price dynamics in U.S beef markets during the pandemic.
= as.data.table(cattle_price_data)
table_data
$date = as.Date(table_data$date)
table_data
=
dt 96:120] %>%
table_data[as.data.frame(dt) %>%
select(date, all_beef_cattle, calves, cows, steer_and_heifers) %>%
gather(key = "price", value = "value", -date)
ggplot(dt, aes(x = date, y = value)) +
labs(title = "Figure 22: U.S. Cattle Prices during COVID-19") +
geom_line(aes(color = price), size = 1) +
scale_color_manual(values = c("orange", "lightblue", "lightgreen", "black")) +
theme_bw()+
+
plot_themegeom_rect(data=dt, aes(xmin = as.Date("2020-02-01", "%Y-%m-%d") , xmax = as.Date("2020-07-01", "%Y-%m-%d") , ymin = 60 , ymax =180),
fill = "transparent", color = "black", size = 1, linetype="dashed")
= as.data.table(beef_price_data[505:624,, c(1:4)])
table_data
$date = as.Date(table_data$date)
table_data
=
dt 96:120] %>%
table_data[as.data.frame(dt) %>%
select(date, farm, wholesale, retail) %>%
gather(key = "price", value = "value", -date)
ggplot(dt, aes(x = date, y = value)) +
labs(title = "Figure 23:U.S. Beef Prices during COVID-19") +
geom_line(aes(color = price), size = 1) +
scale_color_manual(values = c("orange", "lightblue", "lightgreen", "black")) +
theme_bw()+
+
plot_themegeom_rect(data=dt, aes(xmin = as.Date("2020-02-01", "%Y-%m-%d") , xmax = as.Date("2020-07-01", "%Y-%m-%d") , ymin =200 , ymax =770),
fill = "transparent", color = "black", size = 1, linetype="dashed")