[R] plot matrix
John Kane
jrkrideau at inbox.com
Tue Nov 13 18:43:38 CET 2012
Hi,
I didn't see a response for this so here is one way to approach it using the reshape2 and ggplo2 packages.
library(reshape2)
library(ggplot2)
dat1<-read.table(text="
year strong medium healtly
2007 0.606000 0.5101442 0.6226696
2006 1.398500 1.2362115 1.5150000
2005 2.242083 1.9661923 2.4346957
2004 2.981229 2.6141827 3.2402000
2003 3.403312 3.1088077 3.7789478
2002 4.101750 3.8283269 4.5865130
2001 4.991583 4.8069038 5.6671391
",sep="",header=TRUE,stringsAsFactors=FALSE)
str(dat1)
dat2 <- melt(dat1, id=c("year"))
p <- ggplot(dat2, aes(year, value, colour = variable )) + geom_line()
p
John Kane
Kingston ON Canada
> -----Original Message-----
> From: catalinroibu at gmail.com
> Sent: Sun, 11 Nov 2012 13:41:15 +0200
> To: r-help at r-project.org
> Subject: [R] plot matrix
>
> Dear R users,
> I have a problem with plot option in R.
> I want to plot all columns values in a single graph and the labels of x
> axis the row names. I try to use matplot option, but I have a problem
> with
> labels and thickness. I use a very complex data with 10 columns and 406
> rows.
> I use this code:
>> matplot(data.matrix(data1), type="l",xaxt="n")
>> axis(1, labels=row.names(data1),at=1:NROW(data1))
>
> A part of my data is like this:
> strong medium healtly
> 2007 0.606000 0.5101442 0.6226696
> 2006 1.398500 1.2362115 1.5150000
> 2005 2.242083 1.9661923 2.4346957
> 2004 2.981229 2.6141827 3.2402000
> 2003 3.403312 3.1088077 3.7789478
> 2002 4.101750 3.8283269 4.5865130
> 2001 4.991583 4.8069038 5.6671391
>
> Thank you very much!
>
>
>
>
> --
> ---
> Catalin-Constantin ROIBU
> Forestry engineer, PhD
> Forestry Faculty of Suceava
> Str. Universitatii no. 13, Suceava, 720229, Romania
> office phone +4 0230 52 29 78, ext. 531
> mobile phone +4 0745 53 18 01
> +4 0766 71 76 58
> FAX: +4 0230 52 16 64
> silvic.usv.ro
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
More information about the R-help
mailing list