library(ggplot2)
# Use the sunflower dodge position function to arrange and dodge N points.
N <- 300
dat <- data.frame(
x = sample(1:2, size = N, replace = TRUE),
y = sample(1:7, size = N, replace = TRUE),
type = factor(sample(LETTERS[1:2], N, replace = TRUE))
)
# With coord_equal
ggplot(dat, aes(x, y, color = type, shape = type)) +
geom_point(position = position_sunflowerdodge(width = 0.5, density = 2, aspect_ratio = 1)) +
coord_equal()
# Without coord_equal, might want to play with aspect ratio to get a pleasing plot
ggplot(dat, aes(x, y, color = type, shape = type)) +
geom_point(position = position_sunflowerdodge(width = 0.5, density = 10, aspect_ratio = 1/4))
Run the code above in your browser using DataLab