[R] Line chart with a double matrix
David L Carlson
dcarlson at tamu.edu
Thu Jul 19 18:49:14 CEST 2012
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
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of ramonovelar
> Sent: Thursday, July 19, 2012 9:51 AM
> To: r-help at r-project.org
> Subject: [R] Line chart with a double matrix
>
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list