There are several issues here. First, ggplot
parses column names into the aes
without the quotes, thus when you do aes(first, second)
, ggplot2
actually looks for columns named "first"
and "second"
rather the variables that contains the names you parsed.
Second problem is that R doesn't know whats vints
, he thinks it's some object in the global enviroment, thus, you need to tell it that this is a character using "vint1"
My solution will be
grfour1 <- function(gdf, first, second, third, fourth){
gdf <- gdf[c(first, second, third, fourth)]
names(gdf) <- c("first", "second", "third", "fourth")
ggplot(gdf, aes(first, second)) +
geom_point(position = position_jitter(width = 0.2, height = 0)) +
facet_grid(third ~ fourth)
}
library(ggplot2)
grfour1(rndf, "vint1", "vint2", "vch1", "vint2")