Title

dat <- data.frame(x = c("a", "b"), y = runif(20), g = rep(1:10, each = 2))
dat$g <- as.factor(dat$g)

dat
##    x       y  g
## 1  a 0.37620  1
## 2  b 0.46821  1
## 3  a 0.73924  2
## 4  b 0.43202  2
## 5  a 0.34295  3
## 6  b 0.24804  3
## 7  a 0.20613  4
## 8  b 0.28183  4
## 9  a 0.46331  5
## 10 b 0.02378  5
## 11 a 0.09151  6
## 12 b 0.61472  6
## 13 a 0.22766  7
## 14 b 0.37150  7
## 15 a 0.34978  8
## 16 b 0.91942  8
## 17 a 0.87007  9
## 18 b 0.09859  9
## 19 a 0.76906 10
## 20 b 0.25969 10

Plot with no jitter

library(ggplot2)
ggplot(dat, aes(x = x, y = y, group = g)) + geom_point() + geom_line()

plot of chunk unnamed-chunk-2

Plot with separate jitter

ggplot(dat, aes(x = x, y = y, group = g)) + geom_point(position = position_jitter(width = 0.1)) + 
    geom_line(position = position_jitter(width = 0.1))

plot of chunk unnamed-chunk-3

Manually jittered and converted to numeric


dat2 <- dat
dat2$x <- as.numeric(dat2$x)
dat2$x <- jitter(dat2$x)

ggplot(dat2, aes(x = x, y = y, group = g)) + geom_point() + geom_line() + scale_x_continuous(breaks = c(1, 
    2), labels = c("a", "b"))

plot of chunk unnamed-chunk-4