我正在尝试创建一个三个类别之间的比较图表,以及它们随时间变化的价值。 但是,我意识到我系统地做错了,因为不是生成代表3个类别的3行,而是只生成2行。 我已经尝试了不同的值,然而,我意识到我需要在matplot中改变一些东西
你能否就我如何纠正它给你一些见解?
us1 <- data.frame( category = factor(c("Category1","Category1","Category2","Category2","Category3","Category3")),
time = factor(c("1975","2000","1975","2000","1975","2000"),
levels=c("1975","2000")),
values = c(529, 233, 229, 246, 40, 47) )
us1mat <- matrix( us1$values,
nrow = 3,
byrow=TRUE,
dimnames = list(c("Category1","Category2", "Category3"), c("1975", "2000"))
)
usfm_col <- c("blue", "black", "Red")
par(cex=1.2, cex.axis=1.1)
matplot(us1mat, type="b", lty=1, pch=19, col=usfm_col,
cex=1.5, lwd=3, las=1, bty="n", xaxt="n",
xlim=c(0.7, 2.2), ylim=c(0,1000), ylab="",
main="Changes during 1975-2000", yaxt="n")
axis(2, at=axTicks(2), labels=sprintf("$%s", axTicks(2)),
las=1, cex.axis=0.8, col=NA, line = -0.5)
grid(NA, NULL, lty=3, lwd=1, col="#000000")
abline(v=c(1,2), lty=3, lwd=1, col="#000000")
mtext("1975", side=1, at=1)
mtext("2000", side=1, at=2)
答案 0 :(得分:1)
尝试转置数据矩阵:
matplot(t(us1mat), type="b", lty=1, pch=19, col=usfm_col,
cex=1.5, lwd=3, las=1, bty="n", xaxt="n",
xlim=c(0.7, 2.2), ylim=c(0,1000), ylab="",
main="Changes during 1975-2000", yaxt="n")
希望它有效!