Skip to content

Line chart with a double matrix

3 messages · David L Carlson, ramonovelar

#
Hello, 

I have a double matrix that I want to represent in a line chart. Although I
have seen some examples I still don't manage to get it. My data is this (a
double matrix called mymatrix) :

            Blogs Wikis Redes Etiq.   SPC   LMS
Menor de 30 57.14 28.57 14.29 28.57 57.14 28.57
de 31 a 40  63.83 61.70 29.79 17.02 59.57 70.21
de 41 a 50  72.64 70.75 47.17 20.75 55.66 75.47
Mayor de 51 62.07 58.62 48.28 17.24 50.00 67.24

As I understand from  http://www.statmethods.net/graphs/line.html this
example  (see bottom of the page), I have to set the plot and then run a
loop to draw every line.  But:

1) If I do
plot(range(mymatrix), type ="l")
lines(mymatrix[1,],lty="13")

The width of the plot is very small, I just get two columns inside.
Actually, It would like to put the colnames at the bottom of the plot, as
labels and a I would like to calculate the width of the plot to adjust to my
six columns.

2) I don't know how to make a loop for each row of the matrix. Something
like "for (row in mymatrix).

Thanks in advance for any help.
Ram?n

--
View this message in context: http://r.789695.n4.nabble.com/Line-chart-with-a-double-matrix-tp4637047.html
Sent from the R help mailing list archive at Nabble.com.
#
You should include your data using dput(mymatrix) to make things easier

structure(list(Label = structure(c(4L, 1L, 2L, 3L), .Label = c("de 31 a 40", 
"de 41 a 50", "Mayor de 51", "Menor de 30"), class = "factor"), 
    Blogs = c(57.14, 63.83, 72.64, 62.07), Wikis = c(28.57, 61.7, 
    70.75, 58.62), Redes = c(14.29, 29.79, 47.17, 48.28), Etiq. = c(28.57, 
    17.02, 20.75, 17.24), SPC = c(57.14, 59.57, 55.66, 50), LMS = c(28.57, 
    70.21, 75.47, 67.24)), .Names = c("Label", "Blogs", "Wikis", 
"Redes", "Etiq.", "SPC", "LMS"), class = "data.frame", row.names = c(NA, 
-4L))

Then you want matplot() instead of plot() but both plot columns instead of rows so we transpose your data with t()

matplot(t(mymatrix[,2:7]), type="l", xaxt="n")
axis(1, 1:6, colnames(mymatrix)[-1])
legend("bottomright", legend=mymatrix$Label, lty=1:4, col=1:4)

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
#
Thanks David for the solution, I paste here the code with a few changes:

par(xpd = NA, oma = c(5, 0, 0, 0))
matplot(t(buffersump[,1:6]), type="l", xaxt="n", lwd=3, ylab="Porcentajes de
respuestas afirmativas")
axis(1, 1:6, colnames(buffersump2))
legend("bottomright", legend=rownames(buffersump2), lty=1:5, col=1:5,  inset
= c(0, -0.7))



--
View this message in context: http://r.789695.n4.nabble.com/Line-chart-with-a-double-matrix-tp4637047p4637177.html
Sent from the R help mailing list archive at Nabble.com.