data.frame
:
df <- data.frame(id = c("A","A","B","B","C","C"),
age = rep(c("young", "old"), 3),
value = c(20,15,7,5,2,6))
ggplot2
geom_bar
这样,杆件首先被分开(
dodge
d) 借
age
id
(沿x轴,带间隙),并由
身份证件
.
我只熟悉设置
aes(x)
论据
身份证件
和
fill
:
ggplot(df, aes(x = id, y = value)) +
geom_bar(aes(fill = age), position = "dodge", stat = "identity") +
theme_minimal()
或者相反的情况,即
论据
年龄
和
论据
身份证件
:
ggplot(df, aes(x = age, y = value)) +
geom_bar(aes(fill = id), position = "dodge", stat = "identity") +
theme_minimal()
填满
被
身份证件
而不是
年龄
.
position
和/或
stat
价值观得到了这一点。有什么想法吗?