I have a dataframe such as
Seq start end
S1 20 30
S2 25 35
S3 40 45
S4 41 60
S5 20 60
S6 10 30
And I would like to create with ggplot a figure such as :
Where I plot each bar coordinates within the X axis.
There is no preference about the order of the bars within the y axis, but they need to not overlap.
Here is the dput dataframe if it can helps
structure(list(Seq = c("S1", "S2", "S3", "S4", "S5", "S6"), start = c(20L,
25L, 40L, 41L, 20L, 10L), end = c(30L, 35L, 45L, 60L, 60L, 30L
)), class = "data.frame", row.names = c(NA, -6L))
CodePudding user response:
With geom_segment
:
ggplot(data) geom_segment(aes(x = start,
y = Seq,
xend = end,
yend = Seq),
size = 3)
CodePudding user response:
Colored by sequences;
Sample code:
library(ggplot2)
ggplot(df, aes(y = seq, x = start, colour = seq))
geom_segment(aes(yend = seq, xend = end), size = 3)
labs(x = "Position", y="", color="Sequences")
theme_minimal()
Plot:
Sample data:
df<-structure(list(seq = c("S1", "S2", "S3", "S4", "S5", "S6"), start = c(20L,
25L, 40L, 41L, 20L, 10L), end = c(30L, 35L, 45L, 60L, 60L, 30L
)), class = "data.frame", row.names = c(NA, -6L))