title: R Error: Error: `f` must be a factor (or character vector)
body: <p>I'm getting this error:</p>
  
  <pre><code>Error: `f` must be a factor (or character vector)
  </code></pre>
  
  <p>Here is the code.</p>
  
  <pre><code>library(tidyverse)
  library(scales)
  theme_set(theme_light())
  
  recent_grads &lt;- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/recent-grads.csv")
  head(recent_grads)
  
  # recent_grads &lt;- read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/recent-grads.csv")
  majors_processed &lt;- recent_grads %&gt;%
    arrange(desc(Median)) %&gt;%
    mutate(Major = str_to_title(Major),
           Major = fct_reorder(Major, Median))
  
  
  by_major_category &lt;- majors_processed %&gt;%
    filter(!is.na(Total)) %&gt;%
    group_by(Major_category) %&gt;%
    summarize(Men = sum(Men),
              Women = sum(Women),
              Total = sum(Total),
              MedianSalary = sum(as.numeric(Median * Sample_size)) / sum(Sample_size)) %&gt;%
    mutate(ShareWomen = Women / Total) %&gt;%
    arrange(desc(ShareWomen))
  
  
  
  majors_processed %&gt;%
    mutate(Major_category = fct_reorder(Major_category, Median)) %&gt;%
    ggplot(aes(Major_category, Median, fill = Major_category)) +
    geom_boxplot()
  
  
  
  majors_processed %&gt;%
    arrange(desc(Total)) %&gt;%
    head(20) %&gt;%
    mutate(Major = fct_reorder(Major, Total)) %&gt;%
    gather(Gender, Number, Men, Women) %&gt;%
    ggplot(aes(Major, Number, fill = Gender)) +
    geom_col() +
    coord_flip()
  
  
  library(ggrepel)
  by_major_category %&gt;%
    mutate(Major_category = fct_lump(by_major_category, 6)) %&gt;%
    ggplot(aes(ShareWomen, MedianSalary, color = by_major_category)) +
    geom_point() +
    geom_smooth(method = "lm") +
    geom_text_repel(aes(label = by_mjor_category), force = .2) +
    expand_limits(y = 0)
  
  
  library(plotly)
  g &lt;- majors_processed %&gt;%
    mutate(Major_category = fct_lump(Major_category, 4)) %&gt;%
    ggplot(aes(ShareWomen, Median, color = Major_category, size = Sample_size, label = Major)) +
    geom_point() +
    geom_smooth(aes(group = 1), method = "lm") +
    scale_x_continuous(labels = percent_format()) +
    scale_y_continuous(labels = dollar_format()) +
    expand_limits(y = 0)
  ggplotly(g)
  
  
  library(plotly)
  g &lt;- majors_processed %&gt;%
    mutate(Major_category = fct_lump(Major_category, 4)) %&gt;%
    ggplot(aes(ShareWomen, Median, color = Major_category, size = Sample_size, label = Major)) +
    geom_point() +
    geom_smooth(aes(group = 1), method = "lm") +
    scale_x_continuous(labels = percent_format()) +
    scale_y_continuous(labels = dollar_format()) +
    expand_limits(y = 0)
  ggplotly(g)
  
  
  library(broom)
  majors_processed %&gt;%
    select(Major, Major_category, Total, ShareWomen, Sample_size, Median) %&gt;%
    add_count(Major_category) %&gt;%
    filter(n &gt;= 10) %&gt;%
    nest(-Major_category) %&gt;%
    mutate(model = map(data, ~ lm(Median ~ ShareWomen, data = ., weights = Sample_size)),
           tidied = map(model, tidy)) %&gt;%
    unnest(tidied) %&gt;%
    filter(term == "ShareWomen") %&gt;%
    arrange(estimate) %&gt;%
    mutate(fdr = p.adjust(p.value, method = "fdr"))
  
  majors_processed %&gt;%
    filter(Sample_size &gt;= 100) %&gt;%
    mutate(IQR = P75th - P25th) %&gt;%
    arrange(desc(IQR))
  
  
  
  majors_processed %&gt;%
    ggplot(aes(Sample_size, Median)) +
    geom_point() +
    geom_text(aes(label = Major), check_overlap = TRUE, vjust = 1, hjust = 1) +
    scale_x_log10()
  
  knitr::knit_exit()
  
  
  # What were the most common *majors*? (Since there were 173, we're not going to show them all).
  majors_processed %&gt;%
    mutate(Major = fct_reorder(Major, Total)) %&gt;%
    arrange(desc(Total)) %&gt;%
    head(20) %&gt;%
    ggplot(aes(Major, Total, fill = Major_category)) +
    geom_col() +
    coord_flip() +
    scale_y_continuous(labels = comma_format()) +
    labs(x = "",
         y = "Total # of graduates")
  
  
  
  majors_processed %&gt;%
    group_by(Major_category) %&gt;%
    summarize(Median = median(Median)) %&gt;%
    mutate(Major_category = fct_reorder(Major_category, Median)) %&gt;%
    ggplot(aes(Major_category, Median)) +
    geom_col() +
    scale_y_continuous(labels = dollar_format()) +
    coord_flip()
  
  
  # What are the lowest earning majors?
  majors_processed %&gt;%
    filter(Sample_size &gt;= 100) %&gt;%
    tail(20) %&gt;%
    ggplot(aes(Major, Median, color = Major_category)) +
    geom_point() +
    geom_errorbar(aes(ymin = P25th, ymax = P75th)) +
    expand_limits(y = 0) +
    coord_flip()
  </code></pre>
  
  <p>Can someone tell me what's wrong here?  I don't even see an 'f' in the code.  I don't see it as a variable, or anything at all.</p>
  
  <p>I'm following the example here.</p>
  
  <p><a href="https://github.com/dgrtwo/data-screencasts/blob/master/college-majors.Rmd" rel="noreferrer">https://github.com/dgrtwo/data-screencasts/blob/master/college-majors.Rmd</a></p>