循环时,绘图区域顶部和底部的动态轴标记具有一致的间隔数和一致的宽度(ggplot2,grid.ARANGE)
我有一些数据循环时,绘图区域顶部和底部的动态轴标记具有一致的间隔数和一致的宽度(ggplot2,grid.ARANGE),r,ggplot2,grid,gridextra,R,Ggplot2,Grid,Gridextra,我有一些数据 set.seed(123) df <- data.frame(rbind( a = rnorm(4, 60, 30), b = rnorm(4, 30, 15), c = rnorm(4, 10, 5))) spe_a = rnorm(3, mean=0.05, sd=0.003) season = factor(c('Jan','Feb','Mar')) colnames(df) <- c("spe_b","spe_
set.seed(123)
df <- data.frame(rbind(
a = rnorm(4, 60, 30),
b = rnorm(4, 30, 15),
c = rnorm(4, 10, 5)))
spe_a = rnorm(3, mean=0.05, sd=0.003)
season = factor(c('Jan','Feb','Mar'))
colnames(df) <- c("spe_b","spe_c","spe_d","spec_e")
df <- cbind(season, spe_a, df)
# Yes I am sure there is a better method! Please advise in comments?
# I was determine to recreate my problem
set.seed(123)
df使用补丁尝试这种方法,并使用seq()
设置中断。代码如下:
library(patchwork)
library(ggplot2)
#List
plot_list = list()
#Loop
for(i in colnames(df[, 2:5])){
#
plot <- ggplot(data = df,
aes_string(x = season, y = i)) +
geom_bar(stat = 'identity',
fill = 'lightblue') + # For style
ggtitle(i) +
theme(axis.title.y = element_blank()) +
scale_y_continuous(expand = c(0,0),
limits = c(0, max(df[,i])),
breaks = seq(0,max(df[,i]),length.out = 5),
labels = function(x) round(x,2))
#
plot_list[[i]] = plot
#
}
#Plot
G <- wrap_plots(plot_list,ncol = 2)
库(拼凑)
图书馆(GG2)
#名单
plot_list=list()
#环路
对于(i在colnames(df[,2:5])){
#
情节很精彩,谢谢。
library(patchwork)
library(ggplot2)
#List
plot_list = list()
#Loop
for(i in colnames(df[, 2:5])){
#
plot <- ggplot(data = df,
aes_string(x = season, y = i)) +
geom_bar(stat = 'identity',
fill = 'lightblue') + # For style
ggtitle(i) +
theme(axis.title.y = element_blank()) +
scale_y_continuous(expand = c(0,0),
limits = c(0, max(df[,i])),
breaks = seq(0,max(df[,i]),length.out = 5),
labels = function(x) round(x,2))
#
plot_list[[i]] = plot
#
}
#Plot
G <- wrap_plots(plot_list,ncol = 2)