library(readxl)
Fig2_boxplot <- read_excel("D:/plots for PGG/20220308/Fig2_boxplot.xlsx")
head(Fig2_boxplot)
## # A tibble: 6 x 2
## 物种 `Cd (ug/g DW)`
## <chr> <dbl>
## 1 真鲷 0.281
## 2 真鲷 0.187
## 3 真鲷 0.271
## 4 真鲷 0.228
## 5 真鲷 0.183
## 6 真鲷 0.245
Fig2_boxplot[15:20,]
## # A tibble: 6 x 2
## 物种 `Cd (ug/g DW)`
## <chr> <dbl>
## 1 口虾蛄 9.71
## 2 口虾蛄 5.23
## 3 口虾蛄 2.23
## 4 口虾蛄 5.82
## 5 口虾蛄 2.34
## 6 口虾蛄 3.62
tail(Fig2_boxplot)
## # A tibble: 6 x 2
## 物种 `Cd (ug/g DW)`
## <chr> <dbl>
## 1 香港巨牡蛎 17.3
## 2 香港巨牡蛎 25.3
## 3 香港巨牡蛎 35.3
## 4 香港巨牡蛎 43.2
## 5 香港巨牡蛎 48.2
## 6 香港巨牡蛎 72
dat = Fig2_boxplot
library(ggplot2)
dat$物种 = factor(dat$物种, levels = c("香港巨牡蛎", "口虾蛄", "真鲷" ))
ggplot(dat, aes(x=物种, y=`Cd (ug/g DW)`, fill = 物种)) +
geom_boxplot(size = 0.8, alpha=0.6, outlier.colour = 'white') +
geom_jitter(aes(fill=物种),width = 0.2,shape = 21,size=2.8, alpha = 0.4) +
#geom_dotplot(binwidth = 0.1, binaxis='y', stackdir='center', dotsize=1, color = 'white', alpha = 0.6)
scale_fill_manual(values = c("steelblue", "lightsalmon2", "grey")) + theme_bw() + theme(legend.position="none") + scale_y_log10() + theme(panel.border = element_rect(size = 1.5)) + theme(axis.ticks = element_line(size = 1), axis.ticks.length = unit(0.25, 'cm')) + theme(axis.title = element_text(size = 18), axis.text = element_text(size = 16), axis.text.x = element_text(face = 'bold', angle = 325, vjust = 0.2), axis.title.y = element_text(face = 'bold')) + xlab('')