基本上這就是我想要的:

但是,我的資料采用這種格式:
| 國家 | 回復 |
|---|---|
| 西班牙 | 不 |
| 法國 | 是的 |
| 法國 | 不 |
| 法國 | 是的 |
| 英國 | 是的 |
并且基本上想要總結每個國家/地區的“否”和“是”回應
uj5u.com熱心網友回復:
干得好:
library(tidyverse)
# Generate some random data to work with
set.seed(123)
Country <- rep(c("Spain", "France", "UK"), times = c(200,200,200))
Response <- sample(c("Yes", "No"),600, replace = T, prob = c(.3,.6))
df <- data.frame(Country, Response)
# Barplot
p <- df %>% ggplot(aes(x = Country, fill = Response))
geom_bar(position=position_dodge())
ggtitle("Response of each country")
xlab("")
ylab("")
theme_bw()
theme(plot.title = element_text(size = 12, face = "bold", hjust = 0.5))
p
我添加了一些額外的行,以便您可以使用它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471563.html
