ggballonplot 设置轴的限制
ggballonplot set limits for axis
为了使绘图更具可比性,我想将所有填充轴和符号大小轴的限制设置为相同的大小。这可能吗?此外,“大小”和“填充”的图例在最后两个图中交换了位置,我也想防止这种情况发生。
提前致谢!!!
ggballonplot 图表
一些代码作为例子
library(ggplot2)
library(ggpubr)
plot4 <- ggballoonplot(data_matrix_comb, x = "Time", y = "Depth",
size = "mean_percentage_of_indivuals",
fill = "mean_variance", facet.by = "Stage",
ggtheme = theme_bw()) + scale_fill_viridis_c(option = "C") +
labs(title "Autumn")
library(gridExtra)
grid.arrange(plot1, plot2, plot3, plot4, ncol=2, nrow = 2)
您可以使用 ggpubr()
中的 ggarrange()
,我会建议一个常见的图例,因为它有 4 次没有意义。
由于您没有提供,我模拟了一些数据(请以后提供!)。
与您所做的略有不同,我将所有 data.frames 放在一个列表中,如果可能,您应该尝试这样做,这样您就不会 运行 多次使用相同的代码..(即避免复制粘贴代码):
library(ggplot2)
library(ggpubr)
library(dplyr)
set.seed(111)
dat = data.frame(Time=rep(c("day","night"),12),
Depth=rep(c("aphotic","euphotic"),each=2,times=6),
Stage = rep(c("adult","juvenil"),each=4),
mean_percentage_of_indivuals=100*runif(24),
mean_variance = rnbinom(24,mu=100,size=0.5))
dat_all = dat %>% group_by(Time,Depth,Stage) %>% summarize_all(mean)
dat_spring = dat[1:8,]
dat_summer = dat[9:16,]
dat_autumn = dat[17:24,]
dat_list = list("All Seasons"=dat_all,"Spring"=dat_spring,
"Summer"=dat_summer,"Autumn"=dat_autumn)
plts = lapply(names(dat_list),function(i){
p <- ggballoonplot(dat_list[[i]], x = "Time", y = "Depth",
size = "mean_percentage_of_indivuals",
fill = "mean_variance", facet.by = "Stage",
ggtheme = theme_bw()) +
scale_fill_viridis_c(option = "C") +
labs(title=i)
return(p)
})
ggarrange(plotlist =plts,ncol=2, nrow=2, common.legend = TRUE)
为了使绘图更具可比性,我想将所有填充轴和符号大小轴的限制设置为相同的大小。这可能吗?此外,“大小”和“填充”的图例在最后两个图中交换了位置,我也想防止这种情况发生。 提前致谢!!!
ggballonplot 图表
一些代码作为例子
library(ggplot2)
library(ggpubr)
plot4 <- ggballoonplot(data_matrix_comb, x = "Time", y = "Depth",
size = "mean_percentage_of_indivuals",
fill = "mean_variance", facet.by = "Stage",
ggtheme = theme_bw()) + scale_fill_viridis_c(option = "C") +
labs(title "Autumn")
library(gridExtra)
grid.arrange(plot1, plot2, plot3, plot4, ncol=2, nrow = 2)
您可以使用 ggpubr()
中的 ggarrange()
,我会建议一个常见的图例,因为它有 4 次没有意义。
由于您没有提供,我模拟了一些数据(请以后提供!)。
与您所做的略有不同,我将所有 data.frames 放在一个列表中,如果可能,您应该尝试这样做,这样您就不会 运行 多次使用相同的代码..(即避免复制粘贴代码):
library(ggplot2)
library(ggpubr)
library(dplyr)
set.seed(111)
dat = data.frame(Time=rep(c("day","night"),12),
Depth=rep(c("aphotic","euphotic"),each=2,times=6),
Stage = rep(c("adult","juvenil"),each=4),
mean_percentage_of_indivuals=100*runif(24),
mean_variance = rnbinom(24,mu=100,size=0.5))
dat_all = dat %>% group_by(Time,Depth,Stage) %>% summarize_all(mean)
dat_spring = dat[1:8,]
dat_summer = dat[9:16,]
dat_autumn = dat[17:24,]
dat_list = list("All Seasons"=dat_all,"Spring"=dat_spring,
"Summer"=dat_summer,"Autumn"=dat_autumn)
plts = lapply(names(dat_list),function(i){
p <- ggballoonplot(dat_list[[i]], x = "Time", y = "Depth",
size = "mean_percentage_of_indivuals",
fill = "mean_variance", facet.by = "Stage",
ggtheme = theme_bw()) +
scale_fill_viridis_c(option = "C") +
labs(title=i)
return(p)
})
ggarrange(plotlist =plts,ncol=2, nrow=2, common.legend = TRUE)