-1

I want to reproduce a jitterplot in R similar to the one described in Figure 1a of Zack et al., Nature Genetics, 2013:

Plot of interest

I tried the beeswarm functino and the pirate function. The beeswarm function lines the points up to straight and they look like a line has been drawn. I also tried the Pirateplot function and I generally like it, however, I did not figure out how to change the color of different points based on their value on the y-axis as done in the plot from the reference paper.

enter image description here

Eventually, the points should be scattered like in the pirate plot, but colorcoded according to their value on the y-axis.

Anyone any suggestions?

Thanks Tom

Cù Đức Hiếu
  • 5,569
  • 4
  • 27
  • 35
Tom
  • 1
  • 1

1 Answers1

0

I think ggplot2 is the best package to create a jitter plot.

ids <- c(
  rep("id1", 20), 
  rep("id2", 20), 
  rep("id3", 20)
)

values <- runif(60)

classes <- c(
  rep("class1", 30), 
  rep("class2", 30)
)

data <- data.frame(ids, values, classes)

library(ggplot2)

ggplot(data) +
  geom_jitter(
    aes(ids, values, color = classes), 
    width = 0.1
  )

ggplot2 jitter example

nevrome
  • 1,471
  • 1
  • 13
  • 28