Draw a simple box diagram in R language

Draw a simple box diagram in R language

After being introduced by a friend, I wrote a blog for the first time and left a paragraph to record this moment.

#计算天尺度的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 

supplement

I will update my blog from time to time in the future. I hope I can post more articles in the new year, and the R language will go further!

The ultimate goal is to use R to draw "the star of the sheep"! Hahaha.

I wish you all become stronger!

Finally, thank you @桃子鱼gis for your enthusiastic sponsorship!
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46461702/article/details/112391833