# Install packages
if (!requireNamespace("ggbeeswarm", quietly = TRUE)) {
install.packages("ggbeeswarm")
}if (!requireNamespace("ggthemes", quietly = TRUE)) {
install.packages("ggthemes")
}
# Load packages
library(ggbeeswarm)
library(ggthemes)
Beeswarm
Note
Hiplot website
This page is the tutorial for source code version of the Hiplot Beeswarm
plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:
The beeswarm is a noninterference scatter plot which is similar to a bee colony.
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
ggbeeswarm
;ggthemes
Data Preparation
The loaded data are different groups and their data.
# Load data
<- read.table("files/Hiplot/012-beeswarm-data.txt", header = T)
data
# convert data structure
1] <- factor(data[, 1], levels = unique(data[, 1]))
data[, colnames(data) <- c("Group", "y")
# View data
head(data)
Group y
1 G1 5.1
2 G1 4.9
3 G1 4.7
4 G1 4.6
5 G1 5.0
6 G1 5.4
Visualization
# Beeswarm
<- ggplot(data, aes(Group, y, color = Group)) +
p geom_beeswarm(alpha = 1, size = 0.8) +
labs(x = NULL, y = "value") +
ggtitle("BeeSwarm Plot") +
scale_color_manual(values = c("#e04d39","#5bbad6","#1e9f86")) +
theme_stata() +
theme(text = element_text(family = "Arial"),
plot.title = element_text(size = 12,hjust = 0.5),
axis.title = element_text(size = 12),
axis.text = element_text(size = 10),
axis.text.x = element_text(angle = 0, hjust = 0.5,vjust = 1),
legend.position = "right",
legend.direction = "vertical",
legend.title = element_text(size = 10),
legend.text = element_text(size = 10))
p

Different colors represent different groups, and dots represent data.