最终编辑:使用matplot()的结果
我会发现我使用〜3位数字的值来获得更独特的结果,但是基本上这就是我想要的
原始问题
我想创建一个看起来像所附图像的图
我得到的是y和x轴的每一行的值(代表不同的主题)。
接近我找到的有关R绘图的示例,我尝试了以下操作:
arts=c(pt[1,])
g_range <- range(0, arts)
plot(arts, type="o", col="blue", ylim=g_range,axes=FALSE, ann=FALSE)
axis(1, at=1:23, lab=c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23))
box()
这导致错误
xy.coords(x,y,xlabel,ylabel,log)中的错误:
“x”是一个列表,但没有组件“x”和“y”
因此,显然艺术不是这里情节的正确参数,对吧?
旁注:艺术向量中的值被排序为适合0-23的比例
另外:这就是pt的头长的样子
编辑:根据要求,这里是dput(head(pt))的输出
structure(list(`0` = c(2, 1, 0, 0, 0, 0), `1` = c(1, 0, 0, 0,
0, 0), `2` = c(1, 0, 0, 0, 0, 0), `3` = c(0, 0, 0, 0, 0, 0),
`4` = c(0, 0, 0, 0, 0, 0), `5` = c(0, 0, 0, 0, 0, 0), `6` = c(1,
0, 0, 0, 0, 0), `7` = c(1, 0, 0, 0, 0, 0), `8` = c(1, 0,
0, 0, 0, 0), `9` = c(2, 0, 0, 0, 0, 0), `10` = c(2, 1, 0,
0, 0, 0), `11` = c(2, 1, 0, 0, 0, 0), `12` = c(2, 1, 0, 0,
0, 0), `13` = c(2, 1, 0, 0, 0, 0), `14` = c(2, 1, 0, 0, 0,
0), `15` = c(3, 1, 0, 0, 0, 0), `16` = c(3, 1, 0, 0, 0, 0
), `17` = c(3, 1, 0, 0, 0, 0), `18` = c(3, 1, 1, 1, 0, 0),
`19` = c(3, 1, 1, 1, 0, 0), `20` = c(3, 1, 1, 1, 0, 0), `21` = c(3,
1, 1, 1, 0, 0), `22` = c(3, 1, 1, 0, 0, 0), `23` = c(2, 1,
0, 0, 0, 0)), .Names = c("0", "1", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23"), row.names = c(NA, 6L), class = "data.frame")
最佳答案
matplot
可用于将矩阵的每一列绘制为图中的单独线条。您只需要转置矩阵就可以了。有关matplot
的参数的详细信息,请参见?matplot
和?par
,它们控制常规图形参数。
# Generate data
categories <- c("Entertainment", "Games", "Health", "Personal Finance",
"Shopping", "Music", "USSites", "Porn")
colors <- c("green", "blue", "cyan", "yellow", "magenta", "orange",
"red", "black")
markers <- 1:8
pt <- matrix(runif(length(categories)*23), length(categories), 23)
# Plot
matplot(1:23, t(pt), type="l", col=colors, lty=1, pch=markers,
bty="n", las=1, main="Categorical Percent over Time")
legend("topright", col=colors, categories, bg="white", lwd=1, pch=markers)
自从我对均匀分布的随机数据进行采样以来,它看起来非常混乱,但是与您的相比,它看起来要好得多。