I am trying to create a map of transcription factor binding sites on the promoter DNA sequence of some gene by using ggplot2 with geom_segment and geom_text_repel.
This is a a snippet of my data:
mincle.tf <- structure(list(
Matrix.ID = c(
"MA0007.3", "PB0118.1", "MA0608.1",
"MA0474.1", "MA0608.1", "MA0098.2", "MA0007.3", "PB0012.1"
),
Name = structure(c(1L, 5L, 2L, 4L, 2L, 6L, 1L, 3L), .Label = c(
"Ar",
"Creb3l2", "Elf3_1", "Erg", "Esrra_2", "Ets1"
), class = "factor"),
Score = c(
13.8552, 13.7763, 13.6251, 13.0501, 12.9081, 12.7074,
12.6526, 12.4201
), Relative.score = c(
0.8831708, 0.9177318,
0.9736072, 0.9454676, 0.9613641, 0.8977955, 0.8696497, 0.9363881
), Sequence.ID = c(
"seq1", "seq1", "seq1", "seq1", "seq1",
"seq1", "seq1", "seq1"
), Start = c(
603L, 505L, 28L, 873L,
29L, 872L, 603L, 873L
), End = c(
619L, 521L, 36L, 883L, 37L,
886L, 619L, 885L
), Strand = c(
"-", "+", "+", "-", "-", "+",
"+", "-"
), Predicted.sequence = c(
"gggaacataatgtgcat", "gtaaaggggtcagattc",
"tccacgtgt", "agaggaaatga", "gacacgtgg", "atcatttcctctttt",
"atgcacattatgttccc", "aaagaggaaatga"
)
), row.names = c(
NA,
-8L
), class = "data.frame")
This is my code:
ggplot(mincle.tf, aes(Start, 3, label=Name)) +
geom_segment(aes(x=Start, y=3, xend=End, yend=3), size=10, data=mincle.tf[1:8], color=cbp2, alpha=0.5) +
geom_segment(aes(x = 0, y = 3, xend = 1200, yend = 3), size=1, color="black") +
geom_text_repel(data=mincle.tf[1:8],nudge_y = 0.1,point.padding = 0, box.padding = 0, direction = "x", angle=90, hjust=0.5, vjust=0.5)
This is the plot I get:
Basically, I am using geom_segment to draw a line of DNA (black) and colored boxes for TF binding sites, and using geom_text_repel to label each box according to the Name column in the data.
My issue is that the label lines start at the beginning of each box, instead of the center of the box, and I can't quite shorten the length of label lines by point.padding and box.padding. Also, some boxes overlap and I can't figure out the best way to show the overlap. I tried with transparency but was not successful (see a figure below).
At this point, I would really appreciate any suggestions and pointers to make improvements in this plot.




