a <- c('A_1h','A_12h','A_24h','A_48h',
'N_1h','N_12h','N_24h','N_48h',
'P_1h','P_12h','P_24h','P_48h')
group <- rep(c('A','P','N'),each = 4)
compound <- c('Ala','Arg','Asn','Asp','His',
'4-Hydroxybenzoic acid','3-Phenylpropionic acid',
'trans-Cinnamic acid','Phthalic acid',
'Quercetin','Taxifolin','Luteolin',
'NARINGENIN','trans-Chalcone','Isorhamnetin',
'SPM','SPD','PUT')
library(ggplot2)
library(ggprism)
library(RColorBrewer)
df <- data.frame('sample' = a,
'group' = group,
'mean' = runif(12, 1.0, 80.5),
'coefficient' = runif(12, 0.01, 0.1))
df$sd <- df$mean*df$coefficient
colnames(df)
df$sample = factor(df$sample,levels=a)
ggplot(df,aes(x = sample, y = mean, fill = group, col = group))+
geom_bar(stat = 'identity',width = .6)+
ggprism::theme_prism()+
theme(axis.text.x = element_text(angle = 90))+
labs(x= '',y = '',title = compound[1])+
scale_fill_manual(values = brewer.pal(3,'Dark2'))+
scale_color_manual(values = brewer.pal(3,'Dark2'))+
geom_errorbar(#data = df5,
aes(ymin=mean-sd, ymax=mean+sd),
width=.2,
position=position_dodge(0),
show.legend = FALSE,
col = 'black',size = .8)
for (i in 1:18) {
a <- c('A_1h','A_12h','A_24h','A_48h',
'N_1h','N_12h','N_24h','N_48h',
'P_1h','P_12h','P_24h','P_48h')
group <- rep(c('A','P','N'),each = 4)
compound <- c('Ala','Arg','Asn','Asp','His',
'4-Hydroxybenzoic acid','3-Phenylpropionic acid',
'trans-Cinnamic acid','Phthalic acid',
'Quercetin','Taxifolin','Luteolin',
'NARINGENIN','trans-Chalcone','Isorhamnetin',
'SPM','SPD','PUT')
library(ggplot2)
library(ggprism)
library(RColorBrewer)
df <- data.frame('sample' = a,
'group' = group,
'mean' = runif(12, 1.0, 80.5),
'coefficient' = runif(12, 0.01, 0.1))
df$sd <- df$mean*df$coefficient
colnames(df)
df$sample = factor(df$sample,levels=a)
jpeg(filename = paste0(compound[i],".jpg"),
width = 900, height = 750, units = "px",
pointsize = 20)
print(ggplot(df,aes(x = sample, y = mean, fill = group, col = group))+
geom_bar(stat = 'identity',width = .6)+
ggprism::theme_prism()+
theme(text = element_text(size = 24),
axis.text.x = element_text(angle = 90))+
labs(x= '',y = '',title = compound[i])+
scale_fill_manual(values = brewer.pal(3,'Dark2'))+
scale_color_manual(values = brewer.pal(3,'Dark2'))+
geom_errorbar(#data = df5,
aes(ymin=mean-sd, ymax=mean+sd),
width=.2,
position=position_dodge(0),
show.legend = FALSE,
col = 'black',size = .8))
dev.off()
}
R语言for循环绘图
最新推荐文章于 2022-12-01 16:43:37 发布