Package {ggChinaFlag}


Type: Package
Title: Drawing Chinese National and Historical Flags with 'ggplot2'
Version: 0.4.0
Description: Provides programmatic implementations for drawing Chinese national and historical flags using analytic geometry and 'ggplot2'-based vector graphics. Flag designs are constructed entirely from geometric primitives such as polygons and rectangles, without relying on external image files. The package is intended for educational demonstration, reproducible visualization, and procedural graphics in R.
License: GPL-3
Encoding: UTF-8
Imports: ggplot2, dplyr, showtext, ggforce
RoxygenNote: 7.3.3
URL: https://github.com/XLions/ggChinaFlag
BugReports: https://github.com/XLions/ggChinaFlag/issues
Suggests: sysfonts
NeedsCompilation: no
Packaged: 2026-09-12 23:26:48 UTC; liuzhaoshuo
Author: Zhaoshuo Liu ORCID iD [aut, cre]
Maintainer: Zhaoshuo Liu <liuzhaoshuo1997@outlook.com>
Repository: CRAN
Date/Publication: 2026-09-14 09:30:02 UTC

Built-in Chinese and English names of the flags

Description

Provides a standardised list of flag names used by plotCNFlag and related functions. It contains the names of the national flag of the People's Republic of China, several historical flags of the Republic of China, the party flags of the Communist Party of China and the Kuomintang, the regional flags of the Hong Kong and Macao Special Administrative Regions, the flag of the Communist Youth League of China, and the flag of the People's Liberation Army and its service branches, in both Chinese and English.

Usage

FlagStorage(lang = c("Chinese", "English"))

Arguments

lang

Character string giving the language of the returned names. Either "Chinese" (default) or "English".

Value

A list of named character vectors. With lang = "Chinese" the elements hold the Chinese national-flag, political-party, regional-flag, organisation, and military flag names; with lang = "English" they are named National Flags, Political Parties, Regional Flags, Organizations, and Military. The strings in each vector correspond one-to-one to the underlying plotting functions.

See Also

plotCNFlag, which matches against these names.

Examples

# Chinese names
FlagStorage()

# English names
FlagStorage(lang = "English")


Plot a Chinese national, historical, party, regional, organisation, or military flag by name

Description

A unified interface that dispatches to the appropriate low-level plotting function based on the supplied flag name (Chinese or English) and returns a ggplot object.

Usage

plotCNFlag(input, label = TRUE)

Arguments

input

Character string giving the flag to plot, either a Chinese or an English name; see FlagStorage for the supported names.

label

Logical; whether to display the title and text annotations. Default is TRUE.

Details

The function obtains the built-in name list via FlagStorage, detects the input language, matches the name, and forwards to the appropriate plotting function. Supported functions include plot_P.R.CHINA_flag, plot_ROC_KMT_flag, plot_ROC_Beiyang_flag, plot_Han18Star, plot_CCP, plot_KMT, plot_HK_SAR_flag, plot_Macao_SAR_flag, plot_CYLC, and plot_PLA (for the general PLA flag and its service branches). An unrecognised name raises an error.

Value

A ggplot object, which can be printed directly or saved with ggsave().

See Also

FlagStorage for the name list, and the underlying plotting functions such as plot_P.R.CHINA_flag, plot_CYLC, and plot_PLA.

Examples


plotCNFlag("Flag of the People's Republic of China")
plotCNFlag("Flag of the Kuomintang (Blue Sky and White Sun flag)", label = FALSE)
plotCNFlag("Five-Color Flag of the Beiyang Government of the Republic of China")
plotCNFlag("Iron-Blood 18-Star Flag of the Wuchang Uprising")
plotCNFlag("Regional Flag of the Hong Kong Special Administrative Region")
plotCNFlag("Regional Flag of the Macao Special Administrative Region", label = FALSE)
plotCNFlag("\u4e2d\u56fd\u5171\u4ea7\u4e3b\u4e49\u9752\u5e74\u56e2\u56e2\u65d7")
plotCNFlag("\u4e2d\u56fd\u4eba\u6c11\u89e3\u653e\u519b\u6d77\u519b\u519b\u65d7")
plotCNFlag("PLA Rocket Force Flag", label = FALSE)



Plot the emblem or flag of the Communist Party of China (CCP)

Description

This function programmatically renders the emblem of the Communist Party of China using analytic geometry and ggplot2-based vector graphics. The symbol is constructed entirely from geometric primitives (arcs, polygons, and rectangles), without relying on any external image files.

Usage

plot_CCP(plot_type = "flag", label = FALSE)

Arguments

plot_type

Character string specifying the rendering mode. Either "flag" (default) or "logo".

label

Logical value indicating whether to display textual annotations (title and axis labels). Default is FALSE.

Details

Two rendering modes are supported:

The geometric construction follows a stepwise layering strategy, including the outer and inner arcs of the sickle, the handle, and the hammer body. All coordinates are transformed into a unified plotting coordinate system.

Value

A ggplot object representing the CCP emblem or flag.

Author(s)

Per the regulations on the emblem and flag of the Communist Party of China.

See Also

plotCNFlag for the unified flag plotting interface.

Examples


plot_CCP(plot_type = "flag")
plot_CCP(plot_type = "logo")



Plot the flag of the Communist Youth League of China (CYLC)

Description

This function programmatically renders the flag of the Communist Youth League of China using analytic geometry and ggplot2-based vector graphics. The symbol is constructed entirely from geometric primitives (circles, arcs, and polygons), without relying on any external image files.

Usage

plot_CYLC(label = TRUE)

Arguments

label

Logical value indicating whether to display textual annotations (title and axis labels). Default is TRUE.

Details

The geometric construction strictly follows the national standard GB/T 40055-2021.

The geometric construction follows a stepwise layering strategy. It begins with a red rectangular background, followed by a golden circular ring (composed of outer and inner circles), and finally a golden five-pointed star. The star's ten vertices are precisely calculated through line intersection algorithms. Coordinates and radii are scaled according to the 24:16 aspect ratio specified in the standard.

Value

A ggplot object representing the CYLC flag.

Author(s)

Per the national standard GB/T 40055-2021.

See Also

plot_CCP for the CCP emblem/flag plotting interface.

Examples


plot_CYLC(label = TRUE)
plot_CYLC(label = FALSE)



Draw the Regional Flag of the Hong Kong Special Administrative Region

Description

Constructs the flag of the Hong Kong Special Administrative Region of the People's Republic of China entirely from analytic geometry and renders it as a ggplot2 object. The five-petal bauhinia emblem is built by deriving every construction point (circle intersections, line intersections, and rotation angles) from the specification, then replicating a single petal five times at 72-degree increments about the emblem centre.

Usage

plot_HK_SAR_flag(label = TRUE)

Arguments

label

Logical scalar. If TRUE (the default), the plot is annotated with a title and axis captions identifying the standard and drawing reference. If FALSE, all text annotations are suppressed, yielding a bare flag suitable for embedding or export.

Details

The geometry follows the Chinese national standard GB 16689-2004. A single petal is bounded by seven edge segments: six circular arcs drawn on four distinct construction circles, plus one straight chord. Each arc is sampled into a dense polyline (400 points by default) so that geom_polygon can fill the enclosed region; at this sampling density the chordal deviation from the true arc is several orders of magnitude below any practical display or print resolution.

The flag field is a red rectangle with a 3:2 width-to-height ratio, sized relative to the emblem's bounding circle radius. Petals are white and each carries a red five-pointed star.

All construction is performed in a local coordinate system with the emblem's outer circle centred at the origin with radius 60. The function is self-contained: it defines its own geometric helpers internally and depends only on ggplot2 for rendering and showtext for CJK glyph support.

Value

A ggplot object. The object can be printed, further modified with additional ggplot2 layers, or written to disk with ggsave.

Rendering notes

Correct display of the Chinese title and caption requires a font providing CJK glyphs. The function calls showtext_auto, but the user must register a suitable font beforehand, for example via font_add or font_add_google. Without a registered CJK font the non-ASCII labels may render as blank boxes.

The plot uses coord_fixed to enforce a 1:1 aspect ratio; altering the coordinate system will distort the circular arcs.

References

GB 16689-2004. Regional flag of the Hong Kong Special Administrative Region of the People's Republic of China. Standardization Administration of China.

See Also

ggplot, ggsave

Examples


# Register a CJK font before plotting annotated output
if (requireNamespace("sysfonts", quietly = TRUE)) {
  sysfonts::font_add_google("Noto Sans SC", "notosans")
  showtext::showtext_auto()
}

# Annotated flag
plot_HK_SAR_flag()

# Bare flag, no text
plot_HK_SAR_flag(label = FALSE)




Plot the Iron-Blood 18-Star Flag of the Wuchang Uprising

Description

Draws the Iron-Blood 18-Star Flag (also called the Nine-Pointed Eighteen-Star Flag) used by the Hubei military government after the Wuchang Uprising of the Xinhai Revolution. The flag has a red field, a central black nine-pointed star, and nine inner and nine outer yellow dots representing the eighteen Han provinces of the time. All shapes are generated by vector computation, without external image files.

Draws the Iron-Blood 18-Star Flag (also called the Nine-Pointed Eighteen-Star Flag) used by the Hubei military government after the Wuchang Uprising of the Xinhai Revolution. The flag has a red field, a central black nine-pointed star, and nine inner and nine outer yellow dots representing the eighteen Han provinces of the time. All shapes are generated by vector computation, without external image files.

Usage

plot_Han18Star(label = TRUE)

plot_Han18Star(label = TRUE)

Arguments

label

Logical; whether to display the title and explanatory text. TRUE (default) shows the title, designer and historical background; FALSE draws only the flag.

Details

Value

A ggplot object, which can be printed or saved with ggsave().

A ggplot object, which can be printed or saved with ggsave().

Author(s)

Flag design: the Chinese Revolutionary Alliance (Tongmenghui).

References

https://www.19111010.com.tw/story?id=93

https://www.19111010.com.tw/story?id=93

See Also

geom_polygon, geom_circle, plot_P.R.CHINA_flag, plot_ROC_Beiyang_flag, plot_ROC_KMT_flag

geom_polygon, geom_circle, plot_P.R.CHINA_flag, plot_ROC_Beiyang_flag, plot_ROC_KMT_flag

Examples


plot_Han18Star()
plot_Han18Star(label = FALSE)



plot_Han18Star()
plot_Han18Star(label = FALSE)



Plot the Blue Sky with a White Sun flag (Kuomintang / Republic of China)

Description

This function programmatically renders the Blue Sky with a White Sun symbol using analytic geometry and ggplot2-based vector graphics. The emblem consists of a blue background and a twelve-rayed white sun, constructed entirely from geometric primitives such as polygons, circles, and arcs, without relying on any external image files.

Usage

plot_KMT(label = TRUE)

Arguments

label

Logical value indicating whether to display textual annotations (title and axis labels). Default is TRUE.

Details

The geometric construction follows the official construction sheets and historical specifications of the flag, ensuring proportional accuracy of the twelve rays and concentric circles.

The twelve-rayed sun is constructed by alternating outer and inner vertices arranged in clockwise order, forming a closed polygon. Two concentric circles are then overlaid to form the central white sun core.

Value

A ggplot object representing the Blue Sky with a White Sun flag.

Author(s)

Design: Lu Haodong.

References

Wikipedia contributors. Flag of the Republic of China. https://en.wikipedia.org/wiki/Flag_of_the_Republic_of_China

Wikimedia Commons. https://commons.wikimedia.org/wiki/File:Flag_of_the_Republic_of_China_construction_sheet.svg

See Also

plotCNFlag for the unified flag plotting interface.

Examples


plot_KMT()
plot_KMT(label = FALSE)



Draw the Regional Flag of the Macao Special Administrative Region

Description

Constructs the flag of the Macao Special Administrative Region of the People's Republic of China entirely from analytic geometry and renders it as a ggplot2 object. The emblem is assembled from three components, each derived from the specification by computing every construction point (circle intersections, line intersections, and rotation angles): a white lotus flower of three petals, a cluster of five yellow five-pointed stars, and a stylised white bridge with water below. The central petal is constructed explicitly and the two lateral petals follow by mirroring across the vertical axis; the star cluster is positioned by rotating a base location about the lotus anchor point.

Usage

plot_Macao_SAR_flag(label = TRUE)

Arguments

label

Logical scalar. If TRUE (the default), the plot is annotated with a title and axis captions identifying the standard and drawing reference. If FALSE, all text annotations are suppressed, yielding a bare flag suitable for embedding or export.

Details

The geometry follows the Chinese national standard GB 17654-1999. The lotus is bounded by a sequence of circular arcs drawn on numerous distinct construction circles (centres O2-O12, radii such as 649/2, 260/2, and 763/2); each arc is sampled into a dense polyline (400 points by default) so that geom_polygon can fill the enclosed region. At this sampling density the chordal deviation from the true arc is several orders of magnitude below any practical display or print resolution.

The five stars comprise one larger central star flanked by two pairs of smaller stars, all seated on an arc of fixed radius about the emblem anchor O1 at angular offsets of \pm 35^{\circ} and \pm 65^{\circ}. The bridge and water are rendered as five white bands beneath the lotus, each band bounded above and below by arcs of the field's large construction circles and mirrored across the vertical axis.

All construction is performed in a local coordinate system anchored near the emblem base (O1 centred at (0, 38)). The green field is a fixed rectangle spanning \pm 1440 horizontally and \pm 960 vertically, giving a 3:2 width-to-height ratio. The field colour is derived from the spot colour Pantone 355 C (hex #007A4D); the lotus and bridge are white and the stars are yellow (#ffff00). The function is self-contained: it defines its own geometric helpers internally and depends only on ggplot2 for rendering and showtext for CJK glyph support.

Value

A ggplot object. The object can be printed, further modified with additional ggplot2 layers, or written to disk with ggsave.

Rendering notes

Correct display of the Chinese title and caption requires a font providing CJK glyphs. The function calls showtext_auto, but the user must register a suitable font beforehand, for example via font_add or font_add_google. Without a registered CJK font the non-ASCII labels may render as blank boxes.

The plot uses coord_fixed to enforce a 1:1 aspect ratio; altering the coordinate system will distort the circular arcs.

References

GB 17654-1999. Regional flag of the Macao Special Administrative Region of the People's Republic of China. Standardization Administration of China.

See Also

ggplot, ggsave, plot_HK_SAR_flag

Examples


# Register a CJK font before plotting annotated output
if (requireNamespace("sysfonts", quietly = TRUE)) {
  sysfonts::font_add_google("Noto Sans SC", "notosans")
  showtext::showtext_auto()
}

# Annotated flag
plot_Macao_SAR_flag()

# Bare flag, no text
plot_Macao_SAR_flag(label = FALSE)




Plot the national flag of the People's Republic of China

Description

Draws the national flag of the People's Republic of China at the regulation proportions using pure geometric computation and ggplot2. The shape and orientation of the stars are computed analytically so that each small star points to the centre of the large star. No external image or SVG resources are used, which makes the function suitable for teaching and programmatic graphics.

Draws the national flag of the People's Republic of China at the regulation proportions using pure geometric computation and ggplot2. The shape and orientation of the stars are computed analytically so that each small star points to the centre of the large star. No external image or SVG resources are used, which makes the function suitable for teaching and programmatic graphics.

Usage

plot_P.R.CHINA_flag(label = TRUE)

plot_P.R.CHINA_flag(label = TRUE)

Arguments

label

Logical; whether to display the title and axis text. If TRUE (default) the title, designer and reference information are shown; if FALSE only the flag is drawn.

Details

Value

A ggplot object, which can be printed directly or saved with ggsave().

A ggplot object, which can be printed directly or saved with ggsave().

Author(s)

Flag design: Zeng Liansong.

See Also

geom_polygon, coord_quickmap

geom_polygon, coord_quickmap

Examples


plot_P.R.CHINA_flag()
plot_P.R.CHINA_flag(label = FALSE)



plot_P.R.CHINA_flag()
plot_P.R.CHINA_flag(label = FALSE)



Plot the flag of the People's Liberation Army (PLA) or its service branches

Description

This function programmatically renders the flag of the People's Liberation Army of China, as well as the flags of its various service branches and branches, using analytic geometry and ggplot2-based vector graphics. The symbols are constructed entirely from geometric primitives (rectangles, polygons, and stars), without relying on any external image files.

Usage

plot_PLA(subtype = "general", label = TRUE)

Arguments

subtype

Character string specifying the service branch or flag type. Accepts English names (e.g., "PLA Navy") or abbreviations (e.g., "Navy"). Use "general" (default) for the general PLA flag.

label

Logical value indicating whether to display textual annotations (title and axis labels). Default is TRUE.

Details

The function supports both the general PLA flag and a range of service branch flags. The desired flag is selected via the subtype argument, which accepts English names or abbreviations. The matching is performed through a cleaned search table with fuzzy matching to tolerate common prefixes such as "PLA" or "People's Liberation Army".

The geometric construction of the general PLA flag follows the design published by the People's Revolutionary Military Commission on 15 June 1949. The flag has a red background with a golden five-pointed star and the characters "8-1" in the upper left corner. Service branch flags retain the upper 5/8 of the general flag and replace the lower 3/8 with branch-specific colors and patterns.

Supported subtype values include:

Value

A ggplot object representing the requested PLA flag.

Author(s)

Per the regulations on the flag and emblem of the People's Liberation Army.

References

People's Revolutionary Military Commission. Order on the Flag and Emblem of the Chinese People's Liberation Army. People's Daily, 1949-06-15(1).

See Also

plot_CCP for the CCP emblem/flag plotting interface, plot_CYLC for the CYLC flag plotting interface.

Examples


plot_PLA()                          # general PLA flag
plot_PLA("Navy")                    # PLA Navy flag
plot_PLA("PLA Air Force")           # PLA Air Force flag
plot_PLA("Rocket")                  # PLA Rocket Force flag
plot_PLA(subtype = "Support", label = FALSE)



Plot the Five-Colored Flag of the Beiyang Government

Description

Draws the Five-Colored Flag used during the Beiyang Government period (circa 1912-1928) of the Republic of China, using horizontal colour bands rendered with ggplot2. The flag has five equal horizontal stripes in red, yellow, blue, white and black, symbolising the Han, Manchu, Mongol, Hui and Tibetan peoples. The drawing is fully programmatic and uses no external image resources.

Draws the Five-Colored Flag used during the Beiyang Government period (circa 1912-1928) of the Republic of China, using horizontal colour bands rendered with ggplot2. The flag has five equal horizontal stripes in red, yellow, blue, white and black, symbolising the Han, Manchu, Mongol, Hui and Tibetan peoples. The drawing is fully programmatic and uses no external image resources.

Usage

plot_ROC_Beiyang_flag(label = TRUE)

plot_ROC_Beiyang_flag(label = TRUE)

Arguments

label

Logical; whether to display the title and explanatory text. TRUE (default) shows the title and annotations; FALSE draws only the flag.

Details

Value

A ggplot object, which can be printed or saved with ggsave().

A ggplot object, which can be printed or saved with ggsave().

Author(s)

Historical flag of the Beiyang Government era.

See Also

geom_rect, coord_quickmap

geom_rect, coord_quickmap

Examples


plot_ROC_Beiyang_flag()
plot_ROC_Beiyang_flag(label = FALSE)



plot_ROC_Beiyang_flag()
plot_ROC_Beiyang_flag(label = FALSE)



Plot the Blue Sky, White Sun, and a Wholly Red Earth flag

Description

Programmatically draws the Blue Sky, White Sun, and a Wholly Red Earth flag used during the Nationalist Government period (1928-1949) of the Republic of China, using analytic geometry with ggplot2 and ggforce. The flag has a red field, a blue canton in the upper-left, and a twelve-rayed white sun within the canton, all generated from vector geometry without external image files.

Programmatically draws the Blue Sky, White Sun, and a Wholly Red Earth flag used during the Nationalist Government period (1928-1949) of the Republic of China, using analytic geometry with ggplot2 and ggforce. The flag has a red field, a blue canton in the upper-left, and a twelve-rayed white sun within the canton, all generated from vector geometry without external image files.

Usage

plot_ROC_KMT_flag(label = TRUE)

plot_ROC_KMT_flag(label = TRUE)

Arguments

label

Logical; whether to display the title and explanatory text. TRUE (default) shows the title, designer and period; FALSE draws only the flag.

Details

Value

A ggplot object, which can be printed or saved with ggsave().

A ggplot object, which can be printed or saved with ggsave().

Author(s)

Design: Sun Yat-sen (proposal) and Lu Haodong (Blue Sky, White Sun).

See Also

geom_polygon, geom_rect, geom_circle

geom_polygon, geom_rect, geom_circle

Examples


plot_ROC_KMT_flag()
plot_ROC_KMT_flag(label = FALSE)



plot_ROC_KMT_flag()
plot_ROC_KMT_flag(label = FALSE)