StatBin requires a continuous x variable the x variable is discrete

First of all, try to put your question into reprex:

Second, what you want to get is achievable, but you need to understand how ggplot2 works. Namely, when you specify your aesthetics (aes in your code) you are supposed to provide name without quotes since aes is a quoting function (e.g., ggplot(df, aes(x = some_name)) and not (ggplot(df, aes(x = "some_name"))). So, to get the behavior that you want you can do the following:

library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1     ✔ purrr   0.2.4
#> ✔ tibble  1.4.2     ✔ dplyr   0.7.4
#> ✔ tidyr   0.8.0     ✔ stringr 1.3.0
#> ✔ readr   1.1.1     ✔ forcats 0.3.0
#> ── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
df <- tibble::tibble(x = rnorm(100), y = rnorm(100), z = rnorm(100))

Histogram <- function(columnName) {
  DFPlot <- ggplot(data = df, aes_string(x = columnName))
  DFPlot + geom_histogram(bins = 10)
}

Histogram("x")

1 Like