data123
data123

Reputation: 11

Error when plotting using ggplot2: Error in validate_facets(x) : object 'set' not found

I want to plot data in R but I keep getting an error related to facet_grid(-set) which is: Error in validate_facets(x) : object 'set' not found

install.packages('Tmisc')
library(Tmisc)
data(quartet)
View(quartet)

quartet %>%
    group_by(set) %>%
    summarize(mean(x), sd(x), mean(y), sd(y), cor(x,y))
    ggplot(quartet,aes(x,y)) 
        + geom_point() 
        + geom_smooth(method=lm,se=FALSE) 
        + facet_wrap(-set)

> Error in validate_facets(x) : object 'set' not found

Upvotes: 1

Views: 2119

Answers (3)

Héctor Cano
Héctor Cano

Reputation: 1

It works with the code:

ggplot(quartet, 
       aes(x,y)) + 
  geom_point() +
  geom_smooth(method=lm,
              se=FALSE) +
  facet_wrap(~set)

Upvotes: 0

Pratibha
Pratibha

Reputation: 51

Try this code:

install.packages('Tmisc')
library(Tmisc)
data(quartet)
View(quartet)

    quartet %>%
        group_by(set) %>%
        summarize(mean(x), sd(x), mean(y), sd(y), cor(x,y)) %>%
        ggplot(quartet,aes(x,y)) 
            + geom_point() 
            + geom_smooth(method=lm,se=FALSE) 
            + facet_wrap(~set)

you have to use tilde not dash in front of set because set is an independent variable in the quartet dataset. dash is used to remove a column from selection

Upvotes: 5

Khalid Ashik
Khalid Ashik

Reputation: 9

Try to install the tidyverse package and then this command supposed to be work. since ggplot function is under the tidyverse package

Upvotes: -1

Related Questions