# NOT RUN {
library(ggplot2)
library(dplyr)
cacao_small <- cacao %>%
filter(location %in% c("Switzerland", "Canada", "U.S.A.", "Belgium"))
cacao_summary <- cacao_small %>%
group_by(location) %>%
summarize(
sd = sd(rating),
moe = sd*1.96,
rating = mean(rating)
)
ggplot(cacao_summary, aes(x = rating, y = location)) +
stat_confidence_density(aes(moe = moe, fill = stat(ndensity)), height = 0.8) +
geom_point(data = cacao_small, position = position_jitter(width = 0.05), size = 0.3) +
geom_errorbarh(
aes(xmin = rating - sd, xmax = rating + sd),
height = 0.3, color = "darkred", size = 1
) +
geom_point(size = 3, color = "darkred") +
theme_minimal()
library(ggridges)
cacao_se <- cacao_small %>%
group_by(location) %>%
summarize(
se = sd(rating)/sqrt(n()),
moe = se*1.96,
rating = mean(rating)
)
ggplot(cacao_se, aes(x = rating, y = location)) +
stat_confidence_density(
geom = "ridgeline",
aes(moe = moe, height = stat(density)),
alpha = NA, xlim = c(2.5, 3.75), scale = 0.08
) +
theme_minimal()
# }
Run the code above in your browser using DataLab