我目前已经尝试过一门课程,并想在我的r-studio上复制它,但是,为什么提供下面的代码,我只能显示一个单色条形图?它与填充功能的基本颜色有关吗?谢谢!
head(mtcars)
library(ggplot2)
# Bar chart
ggplot(mtcars, aes(x = cyl, fill = am)) +
geom_bar(position = "fill")
# Convert bar chart to pie chart
ggplot(mtcars, aes(x = factor(1), fill = am)) +
geom_bar(position = "fill") +
facet_grid(. ~ cyl) + # Facets
coord_polar(theta = "y") + # Coordinates
theme_void() # theme