A bar plot often starts from category counts. table creates those counts, and barplot maps them to bar heights.

Program

Play the script to add extra no responses and watch the tallest bar change.

barplot_counts.R
responses <- c("yes", "no", "yes", "maybe", "yes", "no")
extra_no <- 
responses <- c(responses, rep("no", extra_no))
counts <- table(responses)
colors <- c(maybe = "gold", no = "tomato", yes = "seagreen")
mids <- barplot(counts, col = colors[names(counts)], main = "Survey", plot = FALSE)
winner <- names(counts)[which.max(counts)]
cat(winner, "\n", sep = "")
responses <- c("yes", "no", "yes", "maybe", "yes", "no")
extra_no <- 
responses <- c(responses, rep("no", extra_no))
counts <- table(responses)
colors <- c(maybe = "gold", no = "tomato", yes = "seagreen")
mids <- barplot(counts, col = colors[names(counts)], main = "Survey", plot = FALSE)
winner <- names(counts)[which.max(counts)]
cat(winner, "\n", sep = "")
responses <- c("yes", "no", "yes", "maybe", "yes", "no")
extra_no <- 
responses <- c(responses, rep("no", extra_no))
counts <- table(responses)
colors <- c(maybe = "gold", no = "tomato", yes = "seagreen")
mids <- barplot(counts, col = colors[names(counts)], main = "Survey", plot = FALSE)
winner <- names(counts)[which.max(counts)]
cat(winner, "\n", sep = "")
table `table(responses)` counts how often each category appears.
barplot `barplot(counts, plot = FALSE)` computes bar positions from category heights.
named vector `colors[names(counts)]` lines colors up with the table's category names.