Categories selection

Hi,
I have a dataset with different categories and I want to drow a scatter plot for each one. This is my actual code:

data <- mtcars
data <- data[8:14,]
plot(data$wt, data$mpg, main="Scatterplot Example",
     xlab="Car Weight ", ylab="Miles Per Gallon ", pch=19)

Is there a better way to select the categories?

This is a possible tidyverse solution:

library(tidyverse)

mtcars %>%
  ggplot(aes(x = wt, y = mpg)) +
  geom_point() +
  facet_wrap(~ cyl)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.