-3
abc=c(8,9,10,11,12,13,14,15,1,2,3,4,5,21,22,23,24,25)

This is composed of 3 samples, where (8:15) is sample 1, (1:5) is sample 2, and (21:25) is sample 3. How can I make a scatter plot with different color?

My "dream plot" should have 3 different color clusters that represent sample 1,2,and 3.

Math Avengers
  • 762
  • 4
  • 15
  • 1
    This is currently very broad. What goes on the x- and y-axes? You only have one variable here. What research have you done? What have you tried, or at least what packages if any are you trying to use? – camille Sep 28 '19 at 20:14
  • plot(), matplot(), map2(), kmean() ...etc – Math Avengers Sep 28 '19 at 20:19
  • 1
    That doesn't give anyone any sense of what you've actually tried or how you're trying to do this. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with, including data that represents the situation. – camille Sep 28 '19 at 21:45

1 Answers1

0

We first add a column with the factor to our dataframe and then we can plot it

library(ggplot2)
library(dplyr)

data.frame(
  abc=c(8,9,10,11,12,13,14,15,1,2,3,4,5,21,22,23,24,25),
  the_factor=c(rep(1,times= 15-8+1), rep(2, times = 5-1+1), rep(3, times = 25-21+1))
) %>% 
  ggplot(aes(x=the_factor, y=abc, col=the_factor %>% as.factor())) +
  geom_point()