# 加载需要的包
library(ggplot2)
## Warning: 程辑包'ggplot2'是用R版本4.2.3 来建造的
# 创建数据
data_4 <- data.frame(
key = rep(1:6, 3),
value = c(
10, 15, 13, 17, 14, 16,
12, 14, 16, 15, 18, 17,
8, 13, 15, 14, 16, 15
),
Sample_name = rep(c("Sample_1", "Sample_2", "Sample_3"), each = 6)
)
data_4
## key value Sample_name
## 1 1 10 Sample_1
## 2 2 15 Sample_1
## 3 3 13 Sample_1
## 4 4 17 Sample_1
## 5 5 14 Sample_1
## 6 6 16 Sample_1
## 7 1 12 Sample_2
## 8 2 14 Sample_2
## 9 3 16 Sample_2
## 10 4 15 Sample_2
## 11 5 18 Sample_2
## 12 6 17 Sample_2
## 13 1 8 Sample_3
## 14 2 13 Sample_3
## 15 3 15 Sample_3
## 16 4 14 Sample_3
## 17 5 16 Sample_3
## 18 6 15 Sample_3
ggplot(data=data_4, aes(x=key, y=value, group=Sample_name, color=Sample_name)) +
geom_smooth(method = "loess", span = 0.5, se = FALSE, size=1.2, alpha = 0.8) +
geom_line(size=1.5, alpha = 0.3) +
geom_point(size=1.5) +
theme(panel.spacing = unit(0.1, "cm"),
legend.position= "top",
legend.title = element_text(size=14),
legend.text = element_text(size=14),
axis.ticks = element_blank(),
axis.line = element_line(colour = "black",
size = 0.5, linetype = "solid"),
axis.text.x = element_blank(),
axis.text.y = element_text(face="plain", color="black", family = "sans",
size=17, angle = 0, hjust = 1),
panel.background = element_rect(fill = "white",
colour = "white",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 1, linetype = 'dashed',
colour = "white"),
axis.title = element_text(color="black", size=14, face="plain", family="sans"))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## i Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## i Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006

##################################
library(ggplot2)
library(patchwork)
## Warning: 程辑包'patchwork'是用R版本4.2.2 来建造的
data_4 <- data.frame(
key = rep(1:6, 3),
value = c(
10, 15, 13, 17, 14, 16,
12, 14, 16, 15, 18, 17,
8, 13, 15, 14, 16, 15
),
Sample_name = rep(c("Sample_1", "Sample_2", "Sample_3"), each = 6)
)
# 定义柔和的颜色
pastel_colors <- c("#FFB3BA", "#BAE1FF", "#BAFFC9") # 柔和的红、蓝、绿
base_theme <- theme(
panel.spacing = unit(0.1, "cm"),
legend.position = "none",
axis.ticks.y = element_line(colour = "black", size = 0.5),
axis.text.y = element_text(face="plain", color="black", family = "sans", size=17),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(size = 1, linetype = 'dashed', colour = "white"),
axis.title.y = element_text(size = 14, angle = 90),
axis.line.y = element_line(colour = "black", size = 0.5),
plot.margin = unit(c(0.2, 1.5, 0.2, 0.5), "cm")
)
p1 <- ggplot(subset(data_4, Sample_name=="Sample_1"), aes(x=key, y=value)) +
geom_smooth(method = "loess", span = 0.5, se = FALSE, size=1.2, alpha = 0.8, color=pastel_colors[1]) +
geom_line(size=0.5, alpha = 0.3, color=pastel_colors[1]) +
geom_point(size=1.5, color=pastel_colors[1]) +
annotate("text", x = 6.5, y = mean(subset(data_4, Sample_name=="Sample_1")$value),
label = "Sample_1", color = pastel_colors[1], size = 6, hjust = 0.5, angle = -90) +
base_theme +
theme(axis.text.x = element_blank(),
axis.line.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x = element_blank())
p2 <- ggplot(subset(data_4, Sample_name=="Sample_2"), aes(x=key, y=value)) +
geom_smooth(method = "loess", span = 0.5, se = FALSE, size=1.2, alpha = 0.8, color=pastel_colors[2]) +
geom_line(size=0.5, alpha = 0.3, color=pastel_colors[2]) +
geom_point(size=1.5, color=pastel_colors[2]) +
annotate("text", x = 6.5, y = mean(subset(data_4, Sample_name=="Sample_2")$value),
label = "Sample_2", color = pastel_colors[2], size = 6, hjust = 0.5, angle = -90) +
base_theme +
theme(axis.text.x = element_blank(),
axis.line.x = element_blank(),
axis.title.x = element_blank(),
axis.ticks.x = element_blank()) +
ylab("Value")
p3 <- ggplot(subset(data_4, Sample_name=="Sample_3"), aes(x=key, y=value)) +
geom_smooth(method = "loess", span = 0.5, se = FALSE, size=1.2, alpha = 0.8, color=pastel_colors[3]) +
geom_line(size=0.5, alpha = 0.3, color=pastel_colors[3]) +
geom_point(size=1.5, color=pastel_colors[3]) +
annotate("text", x = 6.5, y = mean(subset(data_4, Sample_name=="Sample_3")$value),
label = "Sample_3", color = pastel_colors[3], size = 6, hjust = 0.5, angle = -90) +
base_theme +
theme(axis.text.x = element_text(face="plain", color="black", family = "sans", size=17),
axis.line.x = element_line(colour = "black", size = 0.5),
axis.title.y = element_blank(),
axis.ticks.x = element_line(colour = "black", size = 0.5)) +
xlab("Key")
p1 / p2 / p3 + plot_layout(heights = c(1, 1, 1.2))
## `geom_smooth()` using formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006
## `geom_smooth()` using formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006
## `geom_smooth()` using formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006

############################
ggsave(paste0(Sys.Date(),"-ac50.tiff"),
plot = last_plot(), device = NULL, path = NULL,
scale = 1, width = 12, height = 12, units ="cm",dpi = 300,
limitsize = TRUE,compression = "lzw")
## `geom_smooth()` using formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006
## `geom_smooth()` using formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006
## `geom_smooth()` using formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.975
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.1006