ошибка в нечисловом аргументе двоичного оператора

#r #ggplot2

#r #ggplot2

Вопрос:

Это конкретный раздел, вызывающий проблему. Я пытаюсь включить все эти моменты, но, по-моему, я просто неправильно их форматирую. Это также иногда говорит мне, что у меня нет эстетики y, поэтому, если бы вы могли сказать мне, что мне нужно добавить, чтобы исправить эту ошибку, это тоже было бы полезно.

 ggplot(religion)   geom_bar(aes(x=comfort_practice_religion_umprompted, fill=comfort_practice_religion_umprompted, y = ..count../sum(..count..))    labs(x="Comfort Level",y="Proportion",title="Comfort When Asked About Religious Beliefs")   theme_classic()    theme(axis.ticks.y = element_blank(),  axis.ticks.x = element_blank()))  

Вот мой репрекс моего кода:

 library(ggplot2) library(dplyr) #gt;  #gt; Attaching package: 'dplyr' #gt; The following objects are masked from 'package:stats': #gt;  #gt; filter, lag #gt; The following objects are masked from 'package:base': #gt;  #gt; intersect, setdiff, setequal, union library(forcats) religion2 lt;- rename(religion, comfort_practice_religion_umprompted = How.comfortable.would.you.be.seeing.someone.who.practices.a.different.religion.from.you..Ask.you.about.your.religion..unprompted..in.conversation) #gt; Error in rename(religion, comfort_practice_religion_umprompted = How.comfortable.would.you.be.seeing.someone.who.practices.a.different.religion.from.you..Ask.you.about.your.religion..unprompted..in.conversation): object 'religion' not found ggplot(data=religion2)   geom_bar(aes(x=comfort_practice_religion_umprompted, fill=comfort_practice_religion_umprompted)) #gt; Error in ggplot(data = religion2): object 'religion2' not found  religion lt;- mutate(religion2, comfort_practice_religion_umprompted = fct_recode(comfort_practice_religion_umprompted, "No response" = "")) #gt; Error in mutate(religion2, comfort_practice_religion_umprompted = fct_recode(comfort_practice_religion_umprompted, : object 'religion2' not found  religion lt;- mutate(religion2, comfort_practice_religion_umprompted = fct_relevel(comfort_practice_religion_umprompted, "Extremely comfortable","Very comfortable", "Somewhat comfortably", "Not so comfortable", "Not at all comfortable", "No response")) #gt; Error in mutate(religion2, comfort_practice_religion_umprompted = fct_relevel(comfort_practice_religion_umprompted, : object 'religion2' not found  ggplot(religion)   geom_bar(aes(x=comfort_practice_religion_umprompted, fill=comfort_practice_religion_umprompted, y=..count../sum(..count..))) #gt; Error in ggplot(religion): object 'religion' not found dput(religion2)  #gt; Error in dput(religion2): object 'religion2' not found Created on 2021-11-29 by the reprex package (v2.0.1)  

Вот мой вывод dput

 c("Extremely comfortable", "Very comfortable", "Extremely comfortable",  "Very comfortable", "Not so comfortable", "Somewhat comfortably",  "Extremely comfortable", "Somewhat comfortably", "Not so comfortable",  "Very comfortable", "Somewhat comfortably", "Not at all comfortable",  "Extremely comfortable", "Not at all comfortable", "Very comfortable",  "Extremely comfortable", "Very comfortable", "Extremely comfortable",  "Very comfortable", "Very comfortable", "Somewhat comfortably",  "Extremely comfortable", "Not so comfortable", "Extremely comfortable",  "Somewhat comfortably", "Somewhat comfortably", "Somewhat comfortably",  "Not so comfortable", "Very comfortable", "Not at all comfortable",  "Very comfortable", "Not so comfortable", "Very comfortable",  "Extremely comfortable", "Not so comfortable", "Somewhat comfortably",  "Somewhat comfortably", "Not so comfortable", "Very comfortable",  "Not so comfortable", "Very comfortable", "Extremely comfortable",  "Very comfortable", "Extremely comfortable", "Extremely comfortable",  "Not at all comfortable", "Not at all comfortable", "Somewhat comfortably",  "Not so comfortable", "Somewhat comfortably", "Extremely comfortable",  "Not at all comfortable", "Somewhat comfortably", "Very comfortable",  "Extremely comfortable", "Somewhat comfortably", "Somewhat comfortably",  "Somewhat comfortably", "Very comfortable", "Extremely comfortable",  "Extremely comfortable", "Extremely comfortable", "Not so comfortable",  "Very comfortable", "Very comfortable", "Very comfortable", "Not so comfortable",  "Very comfortable", "Not so comfortable", "Not at all comfortable",  "Somewhat comfortably", "Not at all comfortable", "Extremely comfortable",  "Not so comfortable", "Not so comfortable", "Extremely comfortable",  "Somewhat comfortably", "Extremely comfortable", "Very comfortable",  "Somewhat comfortably", "Not at all comfortable", "Somewhat comfortably",  "Not at all comfortable", "", "Not at all comfortable", "Extremely comfortable",  "Somewhat comfortably", "Very comfortable", "Not so comfortable",  "Somewhat comfortably", "Very comfortable", "Somewhat comfortably",  "Extremely comfortable", "Extremely comfortable", "Somewhat comfortably",  "Extremely comfortable", "Not so comfortable", "Very comfortable",  "Somewhat comfortably", "Not so comfortable", "Very comfortable",  "Not so comfortable", "Extremely comfortable", "Not so comfortable",  "Extremely comfortable", "Very comfortable", "Extremely comfortable",   

Я также получаю ошибку в выводе barplot. Это не позволяет мне переименовать розовую полосу в «нет ответа». Я попытался перекодировать его, но это не сработало. График

Комментарии:

1. Что происходит, когда в коде нет ошибок, подобных object 'religion' not found etc? Кроме того, розовая полоса показывает появление «» в вашем объекте. Замените их нужной строкой, чтобы она была в вашем сюжете.

Ответ №1:

Похоже, ваш вопрос состоит из множества проблем. Вы должны сосредоточиться на одной проблеме в одном вопросе. Я рассмотрю проблему, упомянутую в заголовке: «ошибка в нечисловом аргументе двоичного оператора». Это связано с тем, что в ggplot цепочке вы использовали знак плюс ( ) в начале строки, а не в конце, как должно быть (посмотрите перед labs() функцией в вашем примере). Вот как это должно выглядеть:

 ggplot(religion)   geom_bar(aes(x=comfort_practice_religion_umprompted, fill=comfort_practice_religion_umprompted, y = ..count../sum(..count..))    labs(x="Comfort Level",y="Proportion",title="Comfort When Asked About Religious Beliefs")   theme_classic()    theme(axis.ticks.y = element_blank(),  axis.ticks.x = element_blank()))