Visualize using the French flag and the Pentathlon color code (feat. 2024 Paris Olympics)

오륜기 색상코드 이용 시각화 그림
(the French flag and the five-pointed star drawn in R)

From July 26, 2024 to August 11, 2024, the Paris Olympics In memory of Introducing how to draw a five-pointed star and the French flag.you are trying to do. The color codes for the pentameres are #0057B8 (Blue), #FFA300 (Yellow), #000000 (Black), #009B3A (Green), and #EF3340 (Red). Let's use these color codes to plot the Life2.0 terry with R's ggplot2 package.

The pentacle and the French flag

Color codes and what they mean

French flag

오륜기 색상코드 - 프랑스 국기

The French flag is made up of vertical stripes of three colors: blue (#002395), white (#FFFFFF), and red (#ED2939), also known as the "tricolor". Each color is associated with a value of the French Revolution.

  • Blueis Freesymbolized by the colors. It originated from the colors of the Parisian militia during the French Revolution and represents freedom and democracy.
  • White coloris Equalitysymbolizing equality. It was the color of the king of France, and after the Revolution, it came to represent the equality of all people.
  • Redis Philanthropysymbolizing the colors of the French Revolution. It comes from the colors of the revolutionary army during the French Revolution and represents brotherhood and solidarity between people.

Pentathlon color code (Olympic Games)

오륜기 색상코드 - 오륜기 설명

The Olympic flag is the symbol of the Games and consists of five interconnected rings on a white background. The rings are colored blue, yellow, black, green, and red. The five rings represent sportsmanship and solidarity around the world and reflect the Olympic philosophy of "Faster, Higher, Stronger."

  • These five rings are the Five continentssymbolizing the continents. Specifically, it stands for Africa, Asia, Europe, the Americas, and Oceania.
  • The colors of the rings do not refer to the specific colors of each continent, Every country's flag contains at least one colorwhich means that at least one of the following colors is present in the flag of every country: blue (#0057B8), yellow (#FFA300), black (#000000), green (#009B3A), and red (#EF3340).
  • The white background is Peacewhich symbolizes It stands for peace and unity, the spirit of the Olympics.

Shape position and color

The Olympic pentacle and the French flag each have unique colors and placement. To visualize this effectively, it's important to specify exactly where and how each shape is positioned and colored.

The Olympic pentacle is made up of five circles in the colors blue, black, red, yellow, and green, with each circle spaced at regular intervals. The French flag consists of vertical stripes of three colors: blue, white, and red. To represent this configuration in a data visualization, we will use the ggplot2 package.

R Code Explained

1. load the package

First, download the required package ggplot2and gridin the file. ggplot2is a package for data visualization, gridis used to control the layout.

library(ggplot2)
library(grid)

ggplot2is an R package that makes it easy to create a variety of visualizations using data frames. gridis a useful tool for placing multiple graphic elements and setting up layouts.

2. draw Olympic pentathlon function

Define a function to draw the Olympic pentathlon. Assign each of the five circles a color and set the center coordinates.

# Olympic Pentathlon Drawing Function
draw_olympic_flag <- function() { draw_olympic_flag() {
# Olympic Colors
olympic_colors <- c("#0057B8", "#000000", "#EF3340", "#FFA300", "#009B3A")

# Circle center point coordinates (in true circular phase)
centers <- data.frame(
x = c(-1.5, 0, 1.5, -0.75, 0.75),
y = c(0, 0, 0, -0.8, -0.8), # Change the y coordinates of the yellow and green circles from -1 to -0.8
color = olympic_colors
)

# Plotting with ggplot
ggplot() +
geom_point(data = centers, aes(x=x, y=y, color=color), size=30, shape=1, stroke=5) +
scale_color_identity() +
coord_fixed(ratio = 1, xlim = c(-3, 3), ylim = c(-2, 1)) +
theme_void() +
theme(plot.background = element_rect(fill = "white", color = NA))
}

In this function, we specify five colors and the center coordinates of each circle. geom_pointto draw a circle, scale_color_identityto use the specified color as is. coord_fixedto fix the ratio, theme_voidto remove the background and axis.

  • geom_point: A function for drawing circles, drawing a point for each row in the data frame.
  • aesA function that defines an aesthetic mapping, specifying the coordinates and color of the x and y axes.
  • size: Specifies the size of the circle.
  • shape: Specifies the shape of the dot. Here, we set it to a circle.
  • strokeSpecifies the thickness of the circle's border.
  • scale_color_identity: Use the color mapping as is.
  • coord_fixedFixed the ratio of the x-axis to the y-axis.
  • theme_void: Removes axes and background to create a cleaner graph.

3. draw the French flag function

Define a function to draw the flag of France. Specify the three colors: blue, white, and red, and set the vertical stripes.

# French Flag Drawing Function
draw_french_flag <- function() { draw_french_flag()
# France Flag Colors
french_colors <- c("#002395", "white", "#ED2939")

# Flag Ratio
flag_ratio <- 2/3

# Plotting with ggplot
ggplot() +
geom_rect(aes(xmin = 0, xmax = 1, ymin = 0, ymax = 1), fill = french_colors[2]) +
geom_rect(aes(xmin = 0, xmax = 1/3, ymin = 0, ymax = 1), fill = french_colors[1]) +
geom_rect(aes(xmin = 2/3, xmax = 1, ymin = 0, ymax = 1), fill = french_colors[3]) +
coord_fixed(ratio = flag_ratio) +
theme_void()
}

In this function, we specify three colors and their respective rectangle coordinates. geom_rectto draw vertical stripes, coord_fixedto fix the ratio. theme_voidto remove the background and axis.

  • geom_rectA function for drawing a rectangle, specifying the position of the rectangle using xmin, xmax, ymin, and ymax.
  • fill: Specifies the color of the rectangle.
  • coord_fixed: Fixes the ratio of the x-axis to the y-axis to maintain the proportions of the French flag.
  • theme_void: Removes axes and background to create a cleaner graph.

4. draw two flags function

Define a function to draw two flags side by side. grid.layoutand viewportto set up the layout.

# Draw two flags
plot_flags <- function() {
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))

print(draw_olympic_flag(), vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(draw_french_flag(), vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
}

This function creates a new page, sets the layout for 1 row and 2 columns, and draws the Olympic pentagram and the French flag in each viewport.

  • grid.newpage(): Create a new page.
  • pushViewport: Set the viewport to specify the layout.
  • viewport(layout = grid.layout(1, 2)): Create a layout of 1 row 2 columns.
  • print: Output the graph in each viewport.

5. Run the function

Run all functions to draw the flag.

1Execute the # flag drawing
plot_flags()

Common mistakes and how to avoid them

Let's take a look at common mistakes when visualizing and how to avoid them.

  1. Coordinate and color mismatches: In a visualization like the Olympic pentathlon, where specific positions and colors are important, you need to specify exactly where each shape is located and colored. In particular, it's important to set the exact coordinates of the center of each circle of the pentathlon. To do this, we use a data frame to clearly define the coordinates and colors.
  2. Maintain proportions: For visualizations where proportions are important, such as the French flag, use the coord_fixed function to maintain the proportions, otherwise the proportions of the flag may be distorted.
  3. Theme settingsto remove unnecessary axes and background elements. theme_voidin the visualization. This helps keep the visualization clean.

Full code and results

The full source code is shown below.

library(ggplot2)
library(grid)

# Olympic Pentathlon Drawing Function
draw_olympic_flag <- function() { draw_olympic_flag() {
olympic_colors <- c("#0057B8", "#000000", "#EF3340", "#FFA300", "#009B3A")
centers <- data.frame(
x = c(-1.5, 0, 1.5, -0.75, 0.75),
y = c(0, 0, 0, -0.8, -0.8),
color = olympic_colors
)
ggplot() +
geom_point(data = centers, aes(x=x, y=y, color=color), size=30, shape=1, stroke=5) +
scale_color_identity() +
coord_fixed(ratio = 1, xlim = c(-3, 3), ylim = c(-2, 1)) +
theme_void() +
theme(plot.background = element_rect(fill = "white", color = NA))
}

# French Flag Drawing Function
draw_french_flag <- function() { draw_french_flag()
french_colors <- c("#002395", "white", "#ED2939")
flag_ratio <- 2/3
ggplot() +
geom_rect(aes(xmin = 0, xmax = 1, ymin = 0, ymax = 1), fill = french_colors[2]) +
geom_rect(aes(xmin = 0, xmax = 1/3, ymin = 0, ymax = 1), fill = french_colors[1]) +
geom_rect(aes(xmin = 2/3, xmax = 1, ymin = 0, ymax = 1), fill = french_colors[3]) +
coord_fixed(ratio = flag_ratio) +
theme_void()
}

# Draw two flags
plot_flags <- function() {
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
print(draw_olympic_flag(), vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(draw_french_flag(), vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
}

1Execute the # flag drawing
plot_flags()

When you run this code, the Olympic pentathlon and the French flag are drawn side by side, each visualized with the correct colors and proportions, theme_voidto provide a clean result.

Finalizing R-coding for the Paris Olympics

오륜기 색상코드 포스트 - 2024 파리올림픽 로고 그림
( Source: STEPHANE DE SAKUTIN/AFP via Getty Images )

In honor of the 2024 Paris Olympics, we explored the process of plotting the Olympic rings and the French flag using ggplot2. Data visualization is a critical tool for understanding and communicating data. If you'd like to continue learning more visualization techniques, check out the Designing Complex Relationships in R (feat. DiagrammeR)Click on the post!

Today, I'm going to show you how to use R in a way that will help you improve your Life2.0: IT PlaygroundIf you don't know what R is and you want to give it a try, here's a link to the Installing R, RStudio - WindowsCheck out the post!

Similar Posts