最终编辑:使用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")
答案 0 :(得分:7)
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)
由于我只是对均匀分布的随机数据进行采样,因此看起来非常混乱,但是你的看起来会更好。