1

I have the following dummy data:

col1 <- c(1:4, 1:4, 1:4, 1:4)
col2 <- c(168, 2, 40, 12, 2, 60, 16, 3, 70, 20, 15, 11, 200, 150, 1, 100)
col3 <- c(2:5, 2:5, 2:5, 2:5)

dummy_data <- cbind(col1, col2, col3)
dummy_data <- as.data.frame(dummy_data)


ggplot(dummy_data, aes(col1, col3, size = col2))+
  geom_jitter()

Which creates a jitterplot where the x-axis tick marks are "broad", in the sense that the jittered data points have a bigger space to cover in the plot.

Is it possible to create some kind of "box" or lines that will cover this range, as in this picture? I want the range to be very clear to the viewer.

Haakonkas
  • 961
  • 9
  • 26
  • You might want to check this question if you don't mind curly brackets: https://stackoverflow.com/questions/7001799/ggplot2-curly-braces-on-an-axis – acylam Aug 31 '17 at 14:33
  • Thanks! It's nice to be able to choose from brackets and rectangles! – Haakonkas Sep 01 '17 at 07:29

1 Answers1

1

Try this:

ggplot(dummy_data, aes(x = col1))+
  geom_jitter(aes(y = col3, size = col2)) +
  geom_rect(data = data.frame(x = c(1, 2, 3, 4)), 
            aes(xmin = x - 0.5, xmax = x + 0.5, ymin = 1, ymax = 1.5),
            col = "black", fill = NA, inherit.aes = F)

ggplot

You can shift the rectangles up / down via "ymin" & "ymax".

Z.Lin
  • 28,055
  • 6
  • 54
  • 94