ggplot reports a continuous variable is categorical; what am I missing?
up vote
0
down vote
favorite
I'm trying to loop through a dataframe and based on whether the column is a factor or a number return a faceted ggplot. library(tidyverse) d <- mtcars # make a couple factors d2 <- d %>% mutate_at((vars(matches("cyl"),matches("gear"))), as.factor) #check (d2 %>% map_lgl(is.factor)) (d2 %>% map_lgl(is.numeric)) This works: plot_chart <- function(df, na.rm = TRUE){ nm = names(df) for (i in nm) { nm_p <- grep(paste("^",i,"$",sep=""), nm) #finds the position of i in the sequence g <- ggplot(df, aes_string(x = i)) print(nm_p) # progress to console if (is.factor(df[,nm_p])==TRUE) { g <- g + geom_bar() } else if (is.numeric(df[,nm_p])) { g <- g + geom_histogram(bin...