0

I have a dataset with "Status" as one of its columns. In the status variable, the data is either "Employed" or "Left."

I want to visualize only the "Left" entries of the "Status" column.

Currently, I'm only able to visualize both "Employed" and "Left" using this code:

ggplot(data=employee_data) + geom_point(aes(x=satisfaction, y=last_evaluation, color=status))

If I want to isolate only those in "Left" category, how do I do that?

enter image description here

harre
  • 7,081
  • 2
  • 16
  • 28
ninop
  • 23
  • 3
  • 2
    `data=filter(employee_data, status == 'Left')`? – jdobres Aug 10 '22 at 12:52
  • `data=employee_data[employee_data$Status=='Left']`? – wernor Aug 10 '22 at 12:53
  • Hi @jdobres, thanks for the response. Tried this, but it does not work. ggplot(data=filter(employee_data, status == "Left") + geom_point(aes(x=satisfaction, y=last_evaluation, color=status)) – ninop Aug 10 '22 at 12:59
  • 1
    Please add an minimal example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – harre Aug 10 '22 at 13:01
  • @NoelJosephPadilla, if you are indeed using `filter(employee_data, status == "Left")` and plotting that with `ggplot(..., aes(color=status))`, you're saying that you still see points plotted within `status == "Employed"`? ***Really***, please include sample data such as `dput(head(employee_data,20))` in a code block in your question. Thanks! – r2evans Aug 10 '22 at 13:09
  • Seems like you might have made a typo. Should be `ggplot(data=filter(employee_data, status == "Left")) + ...` – jdobres Aug 10 '22 at 13:09
  • @jdobres I revisited the code and it worked now! Thank you so much for your help. – ninop Aug 11 '22 at 11:55

1 Answers1

0

This is done with a simple filter.

ggplot(data = filter(employee_data, status == "left")) + 
geom_point(aes(x = satisfaction, y = last_evaluation, color = status))

Using the iris dataset, you can see the output

ggplot(data = filter(iris, Species == "setosa")) + 
geom_point(aes(x = Petal.Width, y = Petal.Length, color = Species))

filtered plot

amanwebb
  • 380
  • 2
  • 9