как я могу изменить цвет фона при использовании plot_grid?У меня есть следующий рисунок, но я хочу, чтобы все на заднем плане было серым и не должно иметь разницы в высоте.Как я могу изменить это?
Вот мой код для графики и данных:
Данные
set.seed(123456)
Test_1 <- round(rnorm(20,mean=35,sd=3),0)/100
Test_2 <- round(rnorm(20,mean=70,sd=3),0)/100
ei.data <- as.data.frame(cbind(Test_1,Test_2))
intercept <- as.data.frame(matrix(0,20,1))
slope <- as.data.frame(matrix(0,20,1))
data <- cbind(intercept,slope)
colnames(data) <- c("intercept","slope")
for (i in 1:nrow(ei.data)){
data[i,1] <- (ei.data[i,2]/(1-ei.data[i,1]))
data[i,2] <- ((ei.data[i,1]/(1-ei.data[i,1]))*(-1))
}
Левый график
p <- ggplot(data, aes(Test_1,Test_2))+
geom_point(shape=1,size=1)+
theme_bw()+
xlab(TeX("$n_{1,i}$"))+
ylab(TeX("$t_{1,i}$"))+
scale_y_continuous(limits=c(0,1),breaks=seq(0,1,0.2))+
scale_x_continuous(limits = c(0,1),breaks=seq(0,1,0.2))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "grey92", colour = NA),
plot.background = element_rect(fill = "grey92", colour = NA),
axis.line = element_line(colour = "black"))+
theme(aspect.ratio=1)
p
Правый график
df <- data.frame()
q <- ggplot(df)+
geom_point()+
theme_bw()+
scale_y_continuous(limits = c(0, 1),breaks=seq(0,1,0.2))+
scale_x_continuous(limits = c(0, 1),breaks=seq(0,1,0.2))+
xlab(TeX("$\\beta_i^{1,1}"))+
ylab(TeX("$\\beta_i^{2,1}"))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "grey92", colour = NA),
plot.background = element_rect(fill = "grey92", colour = NA), axis.line = element_line(colour = "black"))+
theme(aspect.ratio=1)+
geom_abline(slope =data[1,2] , intercept =data[1,1], size = 0.3)+
geom_abline(slope =data[2,2] , intercept =data[2,1], size = 0.3)+
geom_abline(slope =data[3,2] , intercept =data[3,1], size = 0.3)+
geom_abline(slope =data[4,2] , intercept =data[4,1], size = 0.3)+
geom_abline(slope =data[5,2] , intercept =data[5,1], size = 0.3)+
geom_abline(slope =data[6,2] , intercept =data[6,1], size = 0.3)+
geom_abline(slope =data[7,2] , intercept =data[7,1], size = 0.3)+
geom_abline(slope =data[8,2] , intercept =data[8,1], size = 0.3)+
geom_abline(slope =data[9,2] , intercept =data[9,1], size = 0.3)+
geom_abline(slope =data[10,2] , intercept =data[10,1], size = 0.3)+
geom_abline(slope =data[11,2] , intercept =data[11,1], size = 0.3)+
geom_abline(slope =data[12,2] , intercept =data[12,1], size = 0.3)+
geom_abline(slope =data[13,2] , intercept =data[13,1], size = 0.3)+
geom_abline(slope =data[14,2] , intercept =data[14,1], size = 0.3)+
geom_abline(slope =data[15,2] , intercept =data[15,1], size = 0.3)+
geom_abline(slope =data[16,2] , intercept =data[16,1], size = 0.3)+
geom_abline(slope =data[17,2] , intercept =data[17,1], size = 0.3)+
geom_abline(slope =data[18,2] , intercept =data[18,1], size = 0.3)+
geom_abline(slope =data[19,2] , intercept =data[19,1], size = 0.3)+
geom_abline(slope =data[20,2] , intercept =data[20,1], size = 0.3)
q
Организация
plot_grid(p,q,ncol=2, align = "v")