2

so I am super to new to R, and I have been searching for hours and cant find a way to make this type of scatter plot. I have a data base with 3 columns X, Y, and Z, and I would like to scatter plot Y vs X, but only if Z has an specific value. so my Z has 3 types of values(low, mid, high). I would like to make 3 different graphs one for each value of column Z. Thank you for your help !

P20L
  • 29
  • 3
  • Take a look at [ask] and the guidance on [reproducible R examples](https://stackoverflow.com/q/5963269/5325862). It's really preferable if your question has sample data and code, with a specific debugging question – camille Oct 03 '20 at 21:27

1 Answers1

2

We can use a basic geom_point plot and specify the 'color' as 'Z' as well as make it to 3 plots with `facet_wrap

library(dplyr)
library(ggplot2)
ggplot(df1, aes(x = X, y = Y, color = Z)) + 
     geom_point() + 
     facet_wrap(~ Z)

Using a reproducible example with iris

data(iris)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + 
        geom_point() + 
        facet_wrap(~ Species)
akrun
  • 874,273
  • 37
  • 540
  • 662