我试图让彩色条在使用 geom_bar 绘制它们时相互“躲避”。我还尝试将条形的颜色更改为黑白或灰度。然而,我正在努力通过谷歌搜索来找出为什么我也做不到。你又怎样做呢?谢谢您的帮助!
p <- ggplot() +
geom_bar(aes(x = factor(Pre$preQ17), fill = factor("Pre-Panel")), alpha = 0.5) +
geom_bar(aes(x = factor(Post$postQ7), fill = factor("Post-Panel")), alpha = 0.5, position="dodge") +
labs(title = "Impressions of Prevalence of All Rare Diseases Combined", x = "Prevalence", y = "Number of students", fill = "Survey") +
scale_x_discrete(labels= c("1 in 2", "1 in 5", "1 in 10", "1 in 100", "1 in 1,000", "1 in 10,000", "1 in 100,000")) +
theme(panel.background = element_rect(fill = 'white', colour = 'white')) +
theme(plot.title = element_text(hjust = 0.5))
p
res <- t.test(Pre$preQ17,Post$postQ7)
res
我尝试使用 ggplot() 代替,但这没有成功。我不是一个伟大的程序员。
我无法使用所提供的信息重现您的数据集。请参阅链接此处了解如何询问最小的、可重现的示例。
尽管如此,这有助于回答您的问题吗?
library(tidyverse)
mpg %>%
filter(manufacturer %in% c('audi', 'toyota')) %>% # data wrangling
ggplot() +
geom_bar(aes(x = cty, fill = manufacturer),
position = 'dodge') + # side-by-side rather than stacked
scale_fill_manual(values = c('audi' = 'black', 'toyota' = 'gray')) + # set custom colors
theme_minimal()
创建于 2024-06-20,使用 reprex v2.1.0