Economic flows in a decade of dollar exchange rate graphs: Easily analyze with R
Hello everyone! Today we're going to talk about something that has a huge impact on our daily lives: the dollar exchange rate. Specifically, we're going to look at a 10-year graph of the dollar exchange rate to see how it's been trending in recent years.

In this post, we'll use the A programming language called R.to visualize your data, which will be especially useful if you're interested in data analytics!
Why does the dollar exchange rate matter?
The exchange rate of the Korean Won is one of the most important indicators of the health of our economy. When the exchange rate rises, exporters are happy, but people who enjoy traveling or working abroad are unhappy. Conversely, when the exchange rate falls, imports become less expensive, which is good for consumers, but bad for exporters. In this way, the exchange rate of the Korean won affects every aspect of our lives.
Plot a 10-Year Graph of the Dollar Exchange Rate in R
Now, let's use R to plot a graph of the USD exchange rate over the last 10 years. Follow along with the code below.
Install and load the # package
if (!require("quantmod")) install.packages("quantmod")
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("dplyr")) install.packages("dplyr")
if (!require("zoo")) install.packages("zoo")
library(quantmod)
library(ggplot2)
library(dplyr)
library(zoo)
# Download data from Yahoo Finance
currency_pair <- "USDKRW=X"
start_date <- Sys.Date() - 365*10 # last 10 years
end_date <- Sys.Date()
Get # exchange rate data
getSymbols(currency_pair, src = "yahoo", from = start_date, to = end_date, auto.assign = TRUE)
data <- get(currency_pair)
Handle # missing values
data <- na.omit(data)
Convert to # dataframe
data <- data.frame(Date = index(data), coredata(data))
colnames(data) <- c("Date", "Open", "High", "Low", "Close", "Volume", "Adjusted")
Calculate the # 50-day moving average line
data %
mutate(MA50 = rollmean(Close, k = 50, fill = NA))
Define # major economic events
events <- data.frame(
Date = as.Date(c("2020-03-01", "2022-02-24", "2024-12-07")),
Label = c("COVID-19 Pandemic", "Russia-Ukraine War", "Martial Law Declaration")
)
Calculate the # maximum and minimum exchange rates
max_rate <- max(data$Close, na.rm = TRUE)
min_rate <- min(data$Close, na.rm = TRUE)
max_date <- data$Date[which.max(data$Close)]
min_date <- data$Date[which.min(data$Close)]
# Calculate the 10-year average exchange rate
mean_rate <- mean(data$Close, na.rm = TRUE)
Create a # maximum minimum exchange rate data frame
extreme_points <- data.frame(
Date = c(max_date, min_date),
Rate = c(max_rate, min_rate),
Label = c(paste("Max:", round(max_rate, 2), "on", max_date),
paste("Min:", round(min_rate, 2), "on", min_date))
)
Plot the # graph
ggplot(data, aes(x = Date, y = Close)) +
geom_line(color = "steelblue", size = 1, alpha = 0.8) +
geom_line(aes(y = MA50), color = "orange", size = 1, linetype = "dashed") +
geom_hline(yintercept = mean_rate, color = "blue", linetype = "dotted", size = 1) +
annotate("text", x = max(data$Date), y = mean_rate,
label = paste("10-Year Average:", round(mean_rate, 2)),
color = "blue", vjust = -0.5, hjust = 1, size = 3) +
geom_vline(data = events, aes(xintercept = Date), color = "red", linetype = "dashed", size = 0.7) +
geom_text(data = events, aes(x = Date, y = max(data$Close, na.rm = TRUE), label = Label),
color = "red", vjust = 10, hjust = 1.5, angle = 45, size = 3) +
geom_point(data = extreme_points, aes(x = Date, y = Rate), color = c("green", "purple"), size = 3) +
geom_text(data = extreme_points, aes(x = Date, y = Rate, label = Label),
color = c("green", "purple"), vjust = c(-1, 1.5), hjust = 0.5, size = 3) +
labs(
title = "KRW/USD Exchange Rate Over Last 10 Years",
x = "Year",
y = "Exchange Rate (KRW/USD)"
) + Β
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
axis.title = element_text(size = 12)
)What does a 10-year graph of the dollar exchange rate tell you?

The graph above provides a visual representation of the fluctuations in the KRW/dollar exchange rate over the past decade. It clearly shows the impact of various major domestic and international events on the exchange rate, and provides important clues to understand the interaction of the Korean economy with the global economy over this period. We've summarized some of the most notable points below.
Impact of the COVID-19 pandemic
- In March 2020, the global COVID-19 pandemic declaredThis led to economic uncertainty, which caused the value of the won to depreciate and the demand for dollars as a safe haven asset to skyrocket.
Impact of the Russia-Ukraine war
- In February 2022, Russia's invasion of Ukraine heightened global geopolitical unrest. The energy crisis and global supply chain disruptions intensified, causing the KRW/dollar exchange rate to see another significant rise.
Impact of declaring martial law
- On December 3, 2024, President Yun Seok-yul declared emergency martial law, which had an immediate impact on the foreign exchange market. The increased political instability dampened investor sentiment, which led to a weakening of the won and an increase in the won/dollar exchange rate, which is currently hovering around 1,430 won.
Highs and lows
- According to the graph, on October 24, 2022, the exchange rate will be around 1,443.96In contrast, on April 3, 2018, the peak of 1,053.73at its lowest point.
- These fluctuations are interpreted as a result of a combination of international events and domestic economic policies.
Closing thoughts
Looking at a 10-year graph of the dollar exchange rate, you can see how many different factors affect our economy: interest rates, inflation, international politics, and more. Analyzing and visualizing this data in R makes it easier to understand complex economic phenomena.
Why not use this code to analyze other economic indicators? The data is ready to tell us a lot of stories. Let's listen together!
# Explanation of the code
Below is a line-by-line commentary of the R code that analyzes and visualizes the 10-year data for the graph of the One Dollar Exchange Rate:
if (!require("quantmod")) install.packages("quantmod")
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("dplyr")) install.packages("dplyr")
if (!require("zoo")) install.packages("zoo")
If you don't have the required packages installed, install them.
library(quantmod)
library(ggplot2)
library(dplyr)
library(zoo)
Load the required packages.
currency_pair <- "USDKRW=X"
start_date <- Sys.Date() - 365*10
end_date <- Sys.Date()
Set the currency pair and time period for which you want to get exchange rate data.
getSymbols(currency_pair, src = "yahoo", from = start_date, to = end_date, auto.assign = TRUE)
data <- get(currency_pair)
Download the exchange rate data from Yahoo Finance and assign it to a variable.
data <- na.omit(data)
Remove missing values.
data <- data.frame(Date = index(data), coredata(data))
colnames(data) <- c("Date", "Open", "High", "Low", "Close", "Volume", "Adjusted")
Convert the data to a dataframe and name the columns.
data %
mutate(MA50 = rollmean(Close, k = 50, fill = NA))
Calculate a 50-day moving average line and add it to the data.
events <- data.frame(
Date = as.Date(c("2020-03-01", "2022-02-24", "2024-12-03")),
Label = c("COVID-19 Pandemic", "Russia-Ukraine War", "KR Martial Law Declaration")
)
Define major economic events.
max_rate <- max(data$Close, na.rm = TRUE)
min_rate <- min(data$Close, na.rm = TRUE)
max_date <- data$Date[which.max(data$Close)]
min_date <- data$Date[which.min(data$Close)]
Calculate the maximum and minimum exchange rates and their corresponding dates.
extreme_points <- data.frame(
Date = c(max_date, min_date),
Rate = c(max_rate, min_rate),
Label = c(paste("Max:", round(max_rate, 2), "on", max_date),
paste("Min:", round(min_rate, 2), "on", min_date))
)
Create a dataframe for the maximum and minimum exchange rate points.
ggplot(data, aes(x = Date, y = Close)) +
geom_line(color = "steelblue", size = 1, alpha = 0.8) +
geom_line(aes(y = MA50), color = "orange", size = 1, linetype = "dashed") +
geom_vline(data = events, aes(xintercept = Date), color = "red", linetype = "dashed", size = 0.7) +
geom_text(data = events, aes(x = Date, y = max(data$Close, na.rm = TRUE), label = Label),
color = "red", vjust = 10, hjust = 1.5, angle = 45, size = 3) +
geom_point(data = extreme_points, aes(x = Date, y = Rate), color = c("green", "purple"), size = 3) +
geom_text(data = extreme_points, aes(x = Date, y = Rate, label = Label),
color = c("green", "purple"), vjust = c(-1, 1.5), hjust = 0.5, size = 3) +
labs(
title = "KRW/USD Exchange Rate Over Last 10 Years",
x = "Year",
y = "Exchange Rate (KRW/USD)"
) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
axis.title = element_text(size = 12)
)
Draw a graph using ggplot2. Show the exchange rate data, moving average lines, key events, maximum and minimum exchange rate points, and set the graph title and axis labels. Finally, adjust the theme and style of the graph.



