所以我試圖做一個堆積條形圖。這是所有需要在情節中的數據。我想讓a-e在f-j旁邊。我也試圖讓y軸合理。出於某種原因,它將數字而不是限制。我可能完全錯了。我已經欺騙了R中的堆積條形圖
data<- rbind(c(4655, 4212, 3838, 3583, 3124, 3078, 1411, 2589, 2524, 2429),
c(2826, 2589, 2557, 2713, 2497, 1, 2, 66, 1757, 1822))
a <- cbind(data[, 1], 1, c("50-60", "40-49"))
b <- cbind(data[, 2], 2, c("50-60", "40-49"))
c <- cbind(data[, 3], 3, c("50-60", "40-49"))
d <- cbind(data[, 4], 4, c("50-60", "40-49"))
e <- cbind(data[, 5], 5, c("50-60", "40-49"))
f <- cbind(data[, 6], 1, c("50-60", "40-49"))
g <- cbind(data[, 7], 2, c("50-60", "40-49"))
h <- cbind(data[, 8], 3, c("50-60", "40-49"))
i <- cbind(data[, 9], 4, c("50-60", "40-49"))
j <- cbind(data[, 10], 5, c("50-60", "40-49"))
data <- as.data.frame(rbind(a, b, c, d, e, f, g, h, i, j))
colnames(data) <-c("Number", "Year", "Age")
data$Year <- factor(data$Year, labels = c("FY13",
"FY14","FY15","FY16","FY17"))
library(ggplot2)
ggplot(data = data, aes(x = data$Year, y = Number, fill = Age)) +
geom_bar(stat = "identity")
我可能是完全錯誤的。我看了看,但看不到其他東西來幫助我。
我想說的數字是你的例子中的一個因素,你需要將它轉換爲數字'數據$數字< - as.numeric(數據$數字)'...檢查答案@JanLauGe看看是否這是你需要的... – Umberto