# Install packages
if (!requireNamespace("gggibbous", quietly = TRUE)) {
install.packages("gggibbous")
}if (!requireNamespace("ggplot2", quietly = TRUE)) {
install.packages("ggplot2")
}
# Load packages
library(gggibbous)
library(ggplot2)
Moon charts
Hiplot website
This page is the tutorial for source code version of the Hiplot Moon charts
plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:
The moon chart is a graph that uses the moonβs waxing and waning to reflect the size of the data.
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
gggibbous
;ggplot2
Data Preparation
The loaded data are the name of the restaurant and the number of types of food in the restaurant, the number of decorative style types, the number of tableware sets and the number of price types.
# Load data
<- read.delim("files/Hiplot/122-moon-charts-data.txt", header = T)
data
# Convert data structure
1] <- factor(data[, 1], levels = unique(data[, 1]))
data[, <- colnames(data)[-1]
rest_cols <- reshape(
tidyrest
data,varying = rest_cols,
v.names = "Score",
timevar = "Category",
times = factor(rest_cols, levels = rest_cols),
idvar = colnames(data)[1],
direction = "long"
)
# View data
head(data)
Restaurant
1 Anscombes Luncheonette\t5\t2\t4\t4\nChai Squared\t3\t5\t2\t5\nTukeys Honest Southern Diner
2 Bagels ANOVA
3 Spearmint Row
Food Decor Service Price
1 4 3 3 2
2 4 1 3 5
3 1 5 5 2
Visualization
# Moon charts
<- ggplot(tidyrest, aes(0, 0)) +
p geom_moon(aes(ratio = (Score - 1) / 4), fill = "black") +
geom_moon(aes(ratio = 1 - (Score - 1) / 4), right = FALSE) +
facet_grid(Category ~ Restaurant, switch = "y") +
theme_minimal() +
theme(
panel.grid = element_blank(),
axis.text = element_blank(),
axis.title = element_blank()
)
p

The first row of the diagram shows the name of the restaurant, the first column shows different variables in the restaurant, the blank moon represents the number of 1 (the least number), the black moon represents the number of 5 (the most number) data, as the number of data increases, the black area of the moon gradually becomes larger, that is, gradually becomes full moon.