Desenhe um diagrama de caixa simples na linguagem R
Depois de ser apresentado por um amigo, escrevi um blog pela primeira vez, deixando um parágrafo para registrar esse momento.
#计算天尺度的Q10值
Daytime <- c(1.45, 1.40, 1.37, 1.33, 1.45, 1.30)
Nighttime <- c(1.40, 1.35, 1.37, 1.36, 1.40, 1.37)
Diurnal <- data.frame(Daytime, Nighttime)
Diurnal
library(reshape2)
dfDay <- melt(Diurnal)
dfDay
library(ggplot2)
library(ggsignif)
p1 <- ggplot(dfDay, aes(x = factor(variable), y = value)) +
ggtitle("(a)Diurnal") +
ylab("Q10") +
stat_boxplot(geom = 'errorbar', width = 0.2) +
geom_boxplot(shape = "Type") +
geom_point(shape = 21, size = 1.5) +
ylim(1.28, 1.5) +
theme(plot.title = element_text(vjust = -10, hjust = 0.03)) +
theme(axis.text.x = element_text(size = rel(1.5))) +
theme(axis.text.y = element_text(size = rel(1.5))) +
theme(axis.title.y = element_text(size = 14)) +
theme(axis.title.x = element_blank()) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
panel.border = element_rect(colour = "black", fill = NA))
p1
#计算季节尺度的Q10值
Spring <- c(NA, 1.97, 1.69, 2.20, 1.53, 2.01, 2.41)
Summer <- c(1.28, 1.21, 0.92, 0.75, 1.44, 1.10, 1.05)
Autumn <- c(2.20, 2.37, 2.24, 2.14, 3.26, 2.52, NA)
Winter <- c(1.30, 1.34, 1.09, 1.23, 1.77, 1.13, NA)
Seasonal <- data.frame(Spring, Summer, Autumn, Winter)
Seasonal
dfseason <- melt(Seasonal)
dfseason
p2 <- ggplot(dfseason, aes(x = factor(variable), y = value)) +
ggtitle("(b)Seasonal") +
stat_boxplot(geom = 'errorbar', width = 0.2) +
geom_boxplot(shape = "Type") +
geom_point(shape = 21, size = 1.5) +
theme(plot.title = element_text(vjust = -10, hjust = 0.03)) +
theme(axis.text.x = element_text(size = rel(1.5))) +
theme(axis.text.y = element_text(size = rel(1.5))) +
theme(axis.title.y = element_blank()) +
theme(axis.title.x = element_blank()) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
panel.border = element_rect(colour = "black", fill = NA))
p2
library(patchwork)
p1 + p2
suplemento
Vou atualizar meu blog de vez em quando no futuro. Espero poder postar mais artigos no ano novo, e a linguagem R irá mais longe!
O objetivo final é usar R para desenhar "a estrela das ovelhas"! Hahaha.
Eu desejo que todos vocês se tornem mais fortes!
Finalmente, obrigado @ 桃子 鱼 gis pelo seu patrocínio entusiástico!