title: How to plot histogram and give name to categorial data using R
body: <p>This is the head of my dataset:</p>
  <pre><code>    ï..age sex cp trestbps chol fbs restecg thalach exang oldpeak slope ca thal
  1     63   1  3      145  233   1       0     150     0     2.3     0  0    1
  2     37   1  2      130  250   0       1     187     0     3.5     0  0    2
  3     41   0  1      130  204   0       0     172     0     1.4     2  0    2
  4     56   1  1      120  236   0       1     178     0     0.8     2  0    2
  5     57   0  0      120  354   0       1     163     1     0.6     2  0    2
  6     57   1  0      140  192   0       1     148     0     0.4     1  0    1
    target
  1      1
  2      1
  3      1
  4      1
  5      1
  6      1
  </code></pre>
  <p>I want to plot an histogram based on dependent variable(target) only with the categoral data and chage the value og this data by giving it is names
  I tried this code but not working and give me this error:</p>
  <blockquote>
  <p>Error: Problem with <code>mutate()</code> input <code>thal</code>. x object 'thal' not found
  i Input <code>thal</code> is <code>recode_factor(thal, </code>3<code>= &quot;normal&quot;,</code>6<code>= &quot;fixed defect&quot;,</code>7<code> = &quot;reversible defect&quot;)</code>. Run <code>rlang::last_error()</code> to see
  where the error occurred. In addition: Warning messages: 1: Ignoring
  unknown aesthetics: fill  2: Ignoring unknown aesthetics: fill  3:
  Problem with <code>mutate()</code> input <code>cp</code>. i Unreplaced values treated as NA
  as .x is not compatible. Please specify replacements exhaustively or
  supply .default i Input <code>cp</code> is <code>recode_factor(...)</code>.  4: Unreplaced
  values treated as NA as .x is not compatible. Please specify
  replacements exhaustively or supply .default  5: Problem with
  <code>mutate()</code> input <code>slope</code>. i Unreplaced values treated as NA as .x is
  not compatible. Please specify replacements exhaustively or supply
  .default i Input <code>slope</code> is <code>recode_factor(slope, </code>1<code>= &quot;up-sloaping&quot;,</code>2<code>= &quot;flat&quot;,</code>3<code> = &quot;down-sloaping&quot;)</code>.  6: Unreplaced values treated
  as NA as .x is not compatible. Please specify replacements
  exhaustively or supply .default</p>
  </blockquote>
  <p>and this is my code:</p>
  <pre><code>categorial.df&lt;-df %&gt;% select(2,3,5,6,7,9,11,14)
  
  #Select categorical vars, recode them to their character values, convert to long format
  hd_long_fact_tbl &lt;- categorial.df  %&gt;%
    select(1:8) %&gt;%
    mutate(sex = recode_factor(sex, `0` = &quot;female&quot;, 
                               `1` = &quot;male&quot; ),
           cp = recode_factor(cp, `1` = &quot;typical&quot;,   
                                           `2` = &quot;atypical&quot;,
                                           `3` = &quot;non-angina&quot;, 
                                           `4` = &quot;asymptomatic&quot;),
           fbs = recode_factor(fbs, `0` = &quot;&lt;= 120 mg/dl&quot;, 
                                               `1` = &quot;&gt; 120 mg/dl&quot;),
           restecg = recode_factor(restecg, `0` = &quot;normal&quot;,
                                       `1` = &quot;ST-T abnormality&quot;,
                                       `2` = &quot;LV hypertrophy&quot;),
           exang = recode_factor(exang, `0` = &quot;no&quot;,
                                                   `1` = &quot;yes&quot;),
           slope = recode_factor(slope, `1` = &quot;up-sloaping&quot;,
                                                    `2` = &quot;flat&quot;,
                                                    `3` = &quot;down-sloaping&quot;),
           thal = recode_factor(thal, `3` = &quot;normal&quot;,
                                       `6` = &quot;fixed defect&quot;,
                                       `7` = &quot;reversible defect&quot;)) %&gt;%
    gather(key = &quot;key&quot;, value = &quot;value&quot;, -target)
  #Visualize with bar plot
  hd_long_fact_tbl %&gt;% 
    ggplot(aes(value)) +
    geom_bar(aes(x        = value, 
                 fill     = target), 
             alpha    = .6, 
             position = &quot;dodge&quot;, 
             color    = &quot;black&quot;,
             width    = .8
    ) +
    labs(x = &quot;&quot;,
         y = &quot;&quot;,
         title = &quot;Scaled Effect of Categorical Variables&quot;) +
    theme(axis.text.y  = element_blank(),
      axis.ticks.y = element_blank()) +
    facet_wrap(~ key, scales = &quot;free&quot;, nrow = 4) +
    scale_fill_manual(
      values = c(&quot;#fde725ff&quot;, &quot;#20a486ff&quot;),
      name   = &quot;Heart\nDisease&quot;,
      labels = c(&quot;No HD&quot;, &quot;Yes HD&quot;))
  plot(hd_long_cont_tbl)
  </code></pre>