Here is small example I want to plot (2 group and 2 subgroup, just for simplicity, however I might have n group and k subgroups).
grp <- c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,2, 2, 2,2, 2, 2, 2, 2)
sgrp <- c("A", "A", "A", "A", "A", "B", "B", "B", "B" , "A", "A", "A", "A",
"B", "B", "B", "B", "B")
pos <- c(1.1, 2.1, 3.2, 4.1, 5.0,1.1, 2.0, 5.0, 6.2,1.0, 3.0, 4.1, 5.0,1.0,
2.1, 3.01, 4.0, 5.02)
mydf <- data.frame (grp, sgrp, pos)
grp sgrp pos
1 1 A 1.10
2 1 A 2.10
3 1 A 3.20
4 1 A 4.10
5 1 A 5.00
6 1 B 1.10
7 1 B 2.00
8 1 B 5.00
9 1 B 6.20
10 2 A 1.00
11 2 A 3.00
12 2 A 4.10
13 2 A 5.00
14 2 B 1.00
15 2 B 2.10
16 2 B 3.01
17 2 B 4.00
18 2 B 5.02
Pos determines where ticks need to be in x axis. The central line (long line) starts from zero and ends at maximum position of grp + 1. Is is possible to make such graph ?
The resulting graph should something look like:

Edits:
Here is small trick I could do, but not achieved (not close) what I want to:
dgp <- c(0, 0, 0, 0, 0, 0.15, 0.15,0.15, 0.15 , 0, 0, 0, 0,
0.15, 0.15, 0.15, 0.15, 0.15)
mydf$dumv <- grp + dgp
plot(mydf$pos, mydf$dumv, pch = "+", ylab = "groups", xlab = "pos")

Update again:, got some idea but problems exists:
require(ggplot2)
grp <- c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,2, 2, 2,2, 2, 2, 2, 2)
sgrp <- c("A", "A", "A", "A", "A", "B", "B", "B", "B" , "A", "A", "A", "A",
"B", "B", "B", "B", "B")
position <- c(1.1, 2.1, 3.2, 4.1, 5.0,1.1, 2.0, 5.0, 6.2,1.0, 3.0, 4.1, 5.0,1.0,
2.1, 3.01, 4.0, 5.02)
mydf <- data.frame (grp, sgrp, pos)
dgp <- c(0, 0, 0, 0, 0, 0.15, 0.15,0.15, 0.15 , 0, 0, 0, 0,
0.15, 0.15, 0.15, 0.15, 0.15)
mydf$barheight <- c(0.25)
mydf$group <- grp + dgp
ggplot(mydf) +
geom_line(aes(position, factor(group), group = factor(group)),
size = 2, colour = "purple") +
geom_rect(aes(y = factor(group),
xmin = position - 0.02,
xmax = position + 0.02,
ymin = group - barheight/2,
ymax = group + barheight/2))
Problem: ….
(1) I can not make group non factor, the postion of rectangle are in wrong place, I want to put A, B next to each other while gap between 1 and 2.
(2) In real data, I will have more than two groups, can I automte calculation of dgp.

(I’m not yet a ggplot user, so this is base graphics. You can tweak the

ylimand add aylabargument to properly label. You may want to also useyaxt="n"andaxis()to label your groups and subgroups.)Here’s an alternate setup using the interaction values to pick from a vector of vertical locations.