【发布时间】:2025-12-17 13:05:01
【问题描述】:
我正在尝试制作一个 R ggplot2 图表,其中的列将一个变量分组,而 facet_grid 则由另一个变量分解。我尝试过的两种方法都失败了:
1) 将x 设置为facet_grid 变量会被该变量分解两次:
ggplot(diamonds, aes(x=cut, y=price, fill=color)) +
geom_bar(position="dodge", stat="identity") +
facet_grid(cut ~ ., scales="free")
2) 删除 x 会产生错误:
ggplot(diamonds, aes(y=price, fill=color)) +
geom_bar(position="dodge", stat="identity") +
facet_grid(cut ~ ., scales="free")
# Error in exists(name, envir = env, mode = mode):
# argument "env" is missing, with no default
【问题讨论】: