R 年龄比例的叠加条形图
然而,我不断收到错误消息说 错误:参数2的长度必须为1,而不是1000 (1000与我的本地数据集有关,此处的错误为长度6)R 年龄比例的叠加条形图,r,ggplot2,R,Ggplot2,然而,我不断收到错误消息说 错误:参数2的长度必须为1,而不是1000 (1000与我的本地数据集有关,此处的错误为长度6) 任何帮助都将不胜感激。您想通过p或年龄填写?尝试: ggplot(data = cbind(id = 1,age_prop), aes(x = id, fill = p)) + geom_bar(position = "fill", stat = "identity") + labs(x = "Age Bracke
任何帮助都将不胜感激。您想通过
p
或年龄填写?尝试:
ggplot(data = cbind(id = 1,age_prop), aes(x = id, fill = p)) +
geom_bar(position = "fill", stat = "identity") +
labs(x = "Age Bracket", y = "Proportion")
数据
library(ggplot2)
ggplot(data = df, aes(x = region, y = p, fill = age)) +
geom_bar(position = "fill", stat = "identity") +
labs(x = "Age Bracket", y = "Proportion")
df您在这里所做的一切都很棒。为什么我会得到:“在.Call.graphics(C_palette2,.Call(C_palette2,NULL))中出错:无效的图形状态”?我没有收到任何此类错误。我认为这是某种安装/库错误。您可以尝试重新启动R/R studio并重试吗?如果您仍然面临错误,您可以尝试使用我的帖子中的数据集,并检查它是否适合您使用该数据吗?
library(ggplot2)
ggplot(data = df, aes(x = region, y = p, fill = age)) +
geom_bar(position = "fill", stat = "identity") +
labs(x = "Age Bracket", y = "Proportion")
df <- structure(list(region = c("SSC20005", "SSC20005", "SSC20012",
"SSC20012", "SSC20018", "SSC20018"), age = c("<40", ">=40", "<40",
">=40", "<40", ">=40"), total = c(16L, 17L, 247L, 178L, 50L,
50L), p = c(0.485, 0.515, 0.581, 0.419, 0.5, 0.5)),
class = "data.frame", row.names = c(NA, -6L))