I am having the following code and when I try to call f() then this is giving me the error.
XI am having the following code and when I try to call f() then this is giving me the error.
The code is:
library(tidyverse)
piechart <- function(data, mapping) {
ggplot(data, mapping) +
geom_bar(width = 1) +
coord_polar(theta = "y") +
xlab(NULL) +
ylab(NULL)
}
piechart3 <- function(data, var, ...) {
piechart(data, aes_(~factor(1), fill = substitute(var)))
}
f <- function() {
levs <- c("2seater", "compact", "midsize", "minivan", "pickup",
"subcompact", "suv")
piechart3(mpg, factor(class, levels = levs))
}
f()
And the error is:
"Error in factor(class, levels = levs) : object 'levs' not found".