how to make a graph with unorder data without overlapping?

Dear all,
I have a set of unordered data


for example: scaffold 16 was started from 0.05 mbp to 0.85 mbp but scaffold 18 was started again from 0.05.
I am planning to make "Mbp" as X axis and "Pvalue" as Y axis. However, the scaffold data overlap each other.
Does anyone know how to make a graph with thise data witout overlapping each other?
This is my script

#Chromosome 
library(tidyverse)
library(ggplot2)


data1 = read.csv("data1.csv", header=T)
data2 = read.csv("data2.csv", header=T)

datas = bind_rows(
        data1 %>% mutate(row = row_number()) %>% mutate(df = "A"),
        data2 %>% mutate(row = row_number()) %>% mutate(df = "B"))


# fig theme ##############################################################

mytheme = theme_gray() + theme (panel.grid.major = element_blank(), 
                                panel.grid.minor = element_blank(), 
                                panel.background = element_blank(), 
                                axis.line = element_line(colour = "black"),
                                legend.title=element_blank(),
                                axis.title.x = element_text(size = 15),
                                axis.title.y = element_text(size = 20),
                                text = element_text(size=20),
                                axis.text.y = element_text(hjust=0)
                           
                       + annotate (geom = "rect", 
                                   color = "#D5D8DC", 
                                   fill = "#D5D8DC", alpha = 0.4)
)

theme_set(mytheme)

# Wiring fig ##############################################################
     
A = ggplot(datas, aes(Mbp, Pvalue, color = df))+ 
    geom_jitter(size = 1, alpha = 0.4, width = 0.2) + 
    geom_hline(yintercept=1.4,linetype="dashed") + 
    xlim(-0.1, 20) +
    ylim(0, 50) +
    ylab("-Log10(P)") + 
    xlab("") +
    scale_color_manual(values = c("#0F34E1", "orange"))
                       
A = A + ggtitle("Chromosom") 


These are the data
data1
data2

Please help me.

Hello @amira_ndi ,

you don't use scaffold in your graph(?)
Why not use scaffold with the shape as e.g. in http://www.sthda.com/english/wiki/ggplot2-point-shapes ?

No, I do not use "scaffold". It just for information. But I have to make the graph still continue in each scaffold.
Do you have any idea?

I do not understand what you mean.

I mean,
I would like to make a graph with "Mbp" as X axis and "Pvalue" as Y axis.
However, my data are unorder. Each new scaffold data will be started from "0.05 Mbp", so that the graph will be overlap among scaffold. I would like to make them not overlapping each other. So, the "Pvalue" can continous

Do mean a separate graph for each scaffold?
Then facet_wrap could help.

I tried to search what the "facet-wrap" is. I think It will be a good idea. Do you know, how to add it on my script above?

See e.g. https://ggplot2-book.org/facet.html

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.