thackl / gggenomes

A grammar of graphics for comparative genomics
https://thackl.github.io/gggenomes/
Other
572 stars 64 forks source link

How can I change the distance (spacer) between different seqs? #185

Closed shaodongyan closed 1 month ago

shaodongyan commented 1 month ago

Hi, @iimog @raynamharris @thackl @nschan @thomase4

I love the library but I'm trying to change the distance (spacer) between different seqs if this isn't supported, I used the paramter "spacer" but it does't make sense.

setwd("/Users/R/microbime/heishuimeng/ARC/all/0.95-fullname/FigureS6/tetM////") genes=read.csv("tetM.csv",check.names = F) s0 <- tibble( seq_id = c("tetM_MBBT","tetM_BGAF","tetM_MABT"), length = c(6254,5939,26543) ) emale_links <- gggenomes::read_paf("tetM.paf") genes=as.tibble(genes)

genes$seq_id=factor(genes$seq_id,levels = c("aph(3'')-I_BGBF","aph(3'')-I_MABT","aph(3'')-I_BGAF"))

p_tetM=gggenomes(seq=s0,genes=genes,links = emale_links,spacing = 11000)+ geom_gene(aes(fill=types))+ geom_link()+ geom_seq()+ geom_bin_label(size=4.5)+ scale_fill_lancet()+ geom_gene_tag(aes(label=gene),size=3)+scale_fill_manual(values = c(cols))

image

setwd("/Users/R/microbime/heishuimeng/ARC/all/0.95-fullname/FigureS6/tetM////") genes=read.csv("tetM.csv",check.names = F) s0 <- tibble( seq_id = c("tetM_MBBT","tetM_BGAF","tetM_MABT"), length = c(6254,5939,26543) ) emale_links <- gggenomes::read_paf("tetM.paf") genes=as.tibble(genes)

genes$seq_id=factor(genes$seq_id,levels = c("aph(3'')-I_BGBF","aph(3'')-I_MABT","aph(3'')-I_BGAF"))

p_tetM=gggenomes(seq=s0,genes=genes,links = emale_links,spacing = 0.00001)+ geom_gene(aes(fill=types))+ geom_link()+ geom_seq()+ geom_bin_label(size=4.5)+ scale_fill_lancet()+ geom_gene_tag(aes(label=gene),size=3)+scale_fill_manual(values = c(cols))

image

Sorry,And i used other value such as 10, 100,0.1.....nothing make sense.

Thanks!!!!

nschan commented 1 month ago

I think the spacing parameter controls the distance between sequences, along the x axis, on the same y position. As far as i can tell you only have one sequence per y, so this setting does not affect your plot. If you simply want to have your sequences closer together along the y-axis you should be able to archive that by changing the height of the plot.

thackl commented 1 month ago

Niklas is completely right. If you save the plot as pdf/png etc. you can set height and width. Similarly in Rstudio you can adjust the plot height. ggplot will always try to spread the plot across the given height and width.