Author

Duc Nguyen

Published

July 19, 2026

1 Import

library(readxl)
df <- read_excel("data_group.xlsx")

df <- as.data.frame(df)

df
   GROUP1 GROUP2     GROUP3 VALUE LOWER_CI UPPER_CI
1       A     K1    NH4CL_0 2.447    2.266    2.629
2       A     K1 NH4CL_3.25 2.014    1.841    2.187
3       A     K2    NH4CL_0 3.975    3.786    4.165
4       A     K2 NH4CL_3.25 3.657    3.485    3.829
5       A     K3    NH4CL_0 5.175    5.001    5.348
6       A     K3 NH4CL_3.25 5.379    5.208    5.550
7       B     K1    NH4CL_0 1.356    1.096    1.616
8       B     K1 NH4CL_3.25 1.442    1.185    1.700
9       B     K2    NH4CL_0 1.505    1.224    1.786
10      B     K2 NH4CL_3.25 1.416    1.162    1.671
11      B     K3    NH4CL_0 1.434    1.178    1.690
12      B     K3 NH4CL_3.25 1.253    0.996    1.509

2 Plot

library(ggplot2)

p1 <- ggplot(data = df,
       mapping = aes(x = VALUE,
                     y = GROUP2,
                     color = GROUP3)) +
  
   geom_errorbar(mapping = aes(xmin = LOWER_CI,
                              xmax = UPPER_CI),
                 position = position_dodge2(width = 1),
                 lineend = "square",
                width = 0.5,
                show.legend = T) +
  
  geom_point(shape = 21,
             fill = "white",
             position = position_dodge2(width = 0.5)
             ) +
  
 scale_color_manual(values = c("red", "blue"),
                    name = expression(NH[4]*Cl),
                    labels = c(expression("0%"~NH[4]*Cl),
                              expression("3.25%"~NH[4]*Cl)
                              )) +
  
  guides(color = guide_legend(override.aes = list(size = 3))) +
  
  facet_wrap(~ GROUP1,
             scales = "fixed") +
  
  labs(x = "Percent (%)",
       y = "") +
  
  theme_bw(base_size = 16) +

  theme(axis.title = element_text(color = "black")) +

  theme(axis.text = element_text(color = "black")) +
  
  theme(axis.ticks = element_line(color = "black")) +

  theme(strip.text = element_text(color = "black")) +
  
  theme(legend.key.width = unit(1, "cm"))

p1
ggsave(filename = "dot-plot-group.png",
       plot = p1,
       width = 9,
       height = 3,
       dpi = 300,
       units = "in")

Để vẽ được các đồ thị khoa học đạt chuẩn công bố quốc tế, bạn có thể tham gia lớp R for Data Science do mình trực tiếp hướng dẫn. Thông tin chi tiết