具有不同颜色变量和平均线的绘图
我在的
r
中有一个中的数据集[ - 1,1]
5个国家,即(a,b,b,c,d,e)
代码>如下:
data <- matrix(runif(n=50, min = -1, max = 1),ncol = 5)
data <- round(data,2)
colnames(data) <-
c("A", "B", "C", "D", "E")
然后,我计算所有国家/地区的每行的平均值:
aver <- as.matrix(rowMeans(data))
rownames(aver) <- c("X1","X2","X3","X4","X5","X6","X7","X8","X9","X10")
我想创建一个带有每个国家/国家(列)的观测值的图,以具有不同的颜色,aver
要包括的行。我正在使用以下内容,但无法正常工作。
plot(c(data),col=c("red","yellow","green","blue","black"))
lines(aver)
我该怎么做?
I have a dataset in R
of values in [-1,1]
for 5 countries, namely (A,B,C,D,E)
as follows:
data <- matrix(runif(n=50, min = -1, max = 1),ncol = 5)
data <- round(data,2)
colnames(data) <-
c("A", "B", "C", "D", "E")
Then I calculate the average value of each row for all countries with the following:
aver <- as.matrix(rowMeans(data))
rownames(aver) <- c("X1","X2","X3","X4","X5","X6","X7","X8","X9","X10")
I want to create a plot with the observations with each country (column) to have different colors and the aver
line to be included. I am using the following but can not make it properly work.
plot(c(data),col=c("red","yellow","green","blue","black"))
lines(aver)
The final result must look like this but with colored observations included:
How can I do that??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您想要这样的东西:
输出:
为传奇添加此信息:
输出:
Maybe you want something like this:
Output:
Add this for legend:
Output: