我正在制作一个 geom_col 图,它根据分类类别填充颜色,x 是组,y 是丰富的,这是我的代码:
sig_counts_rowsample <- data.frame(t(sig_counts))%>%
merge(.,anno_col,by=0)%>%
pivot_longer(.,cols=2:(length(.)-1), names_to = "taxa", values_to = "abundance")
options(scipen=10000)
p<-ggplot(sig_counts_rowsample) +
geom_col(aes(x=Group, y=abundance,fill=factor(taxa,levels=bar_sorting)),position = "position_stack(reverse = TRUE)")+
scale_fill_discrete(name = "Taxa")
output_name<-paste("Group_statistics/Sig_abundance",mtype,"barplot.svg",sep="_")
ggsave(output_name,plot=p,device="svg",units="cm",width=35,height=18)
这是数据框的样子:
> sig_counts_rowsample
# A tibble: 1,491 x 4
Row.names Group taxa abundance
<I<chr>> <fct> <chr> <dbl>
1 L1-0 L0 g__Desulfallas_s__gibsoniae 0
2 L1-0 L0 g__Streptococcus_s__thermophilus 0
3 L1-0 L0 g__Streptococcus_s__agalactiae 0
4 L1-0 L0 g__Streptococcus_s__acidominimus 0
5 L1-0 L0 g__Clostridium_s__cellulovorans 358.
6 L1-0 L0 g__Lactobacillus_s__reuteri 30.4
7 L1-0 L0 g__Lactobacillus_s__sakei 40.7
8 L1-0 L0 g__Lactobacillus_s__alimentarius 49.6
9 L1-0 L0 g__Hungateiclostridium_s__saccincola 0
10 L1-0 L0 g__Corynebacterium_s__ammoniagenes 39.2
我做了一些修改来对填充颜色和条的顺序进行排序。这是我的 jpg 输出:
但是,当我将其保存为 svg 格式(如上面的代码)时,条形框架会非常明显,我希望它看起来与 jpg 图片相同,我该怎么做?
这是 svg 输出的截图(因为我不能在这里上传 svg 文件)