Search code examples
rggplot2data-visualizationcategorical-data

How do I selectively visualize data in a categorical column in R?


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


Solution

  • 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