gpt4 book ai didi

R绘制列表的行

转载 作者:行者123 更新时间:2023-12-01 10:04:04 24 4
gpt4 key购买 nike

最终编辑:使用 matplot() 的结果我会确保我使用 ~3 位数的值来获得更独特的结果,但基本上这就是我想要的 enter image description here

原始问题


我想创建一个应该看起来像附加图像的图表 graph should look like this

我得到的是 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()

这会导致错误

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'

显然艺术不是这里情节的正确参数,对吧?旁注:arts 向量中的值按 0-23 的比例排序

另外:pt的头部是这样的enter image description here

编辑:根据要求,这里是 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)

enter image description here

它看起来非常困惑,因为我只是对均匀分布的随机数据进行采样,但它看起来会比你的好得多。

关于R绘制列表的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12640122/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com