Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
155 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...