![]() |
|
|
|
#1 |
|
TS Contributor
Join Date: Sep 2008
Location: Australia
Posts: 488
Thanks: 26
Thanked 81 Times in 79 Posts
![]() |
R: levelplot
I am having trouble finishing a level plot in R.
The Y axis is a catergory of substrate and the x axis is the site, with the matrix being the percent of the subtrate type at each site. My problem (I think) is that I have created a mtrix but R is not recognising the column and row names I have assigned them. I would like to: A) plot the y axis with the Column names and xaxis with the row names B) place the color key under the xaxis. I don't often use matrices in R (Usually i read them in as csv files). I am guessing this might be much easier to create this plot if I read in my spread sheet as a matrix, but I am not too sure how to go about it. Any help would be much appreciated? ! see below for code (so far....) #################### library(lattice) rock=matrix(c(0,0,0,0,0,0,0,0,10,5,10,5,5,5,15,0,1 0,10,20,20,0,15,15,20,30,0,45,40,30,30,20,15,15,10 ,0,70,10,15,5,0),5,8, dimnames=list(c("MUR 0931","MUR 28","MUR 0935","MUR 0937","MUR 29"), c("Clay", "Silt", "Sand", "Gravel", "Pebble", "Cobble", "Boulder", "Bedrock"))) levelplot(rock,xlab="Site", cuts=12.5,ylab="Substrate type" ,colorkey=TRUE, at=c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75 ,80,85,90,95,100), col.regions=(col=gray((30:100)/100))) axis(1, 1:5, labels=rownames(rock), las=1) axis(2, 1:8, labels=colnames(rock), las=1) Last edited by TheEcologist; 10-19-2009 at 02:58 AM. Reason: Removed errors from script, bugman what version of R r u using? |
|
|
|
|
|
#2 | ||
|
Super Moderator
Join Date: Mar 2008
Location: The Netherlands.
Posts: 506
Thanks: 11
Thanked 94 Times in 87 Posts
![]() |
Quote:
This works for me: Code:
library(lattice)
rock=matrix(c(0,0,0,0,0,0,0,0,10,5,10,5,5,5,15,0,10,10,20,20,0,15,15,20,30,0,45,40,30,30,20,15,15,10,0,70,10,15,5,0),5,8,
dimnames=list(c("MUR 0931","MUR 28","MUR 0935","MUR 0937","MUR 29"),
c("Clay", "Silt", "Sand", "Gravel", "Pebble", "Cobble", "Boulder", "Bedrock")))
levelplot((rock),xlab="Site", cuts=12.5,ylab="Substrate type" ,colorkey=list(space='bottom'), at=c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100), col.regions=(col=gray((30:100)/100)))
Quote:
rock=matrix(read.table('clipboard'),dimnames=list( c("MUR 0931","MUR 28","MUR 0935","MUR 0937","MUR 29"), c("Clay", "Silt", "Sand", "Gravel", "Pebble", "Cobble", "Boulder", "Bedrock")))
__________________
The true ideals of great philosophies always seem to get lost somewhere along the road.. |
||
|
|
|
| The Following User Says Thank You to TheEcologist For This Useful Post: | bugman (10-19-2009) |
|
|
#3 |
|
TS Contributor
Join Date: Sep 2008
Location: Australia
Posts: 488
Thanks: 26
Thanked 81 Times in 79 Posts
![]() |
Thanks for this!
copy & paste your spreadsheet matrix, go into R and type this; rock=matrix(read.table('clipboard'),dimnames=list( c("MUR 0931","MUR 28","MUR 0935","MUR 0937","MUR 29"), c("Clay", "Silt", "Sand", "Gravel", "Pebble", "Cobble", "Boulder", "Bedrock")))[/quote] Though please excuse my ignorance - where do I paste it? (FYI: I have the matrix as a csv file). I tried it, but got this warning in return... ####### In read.table("clipboard") : incomplete final line found by readTableHeader on 'clipboard' ################# |
|
|
|
|
|
#4 |
|
Super Moderator
Join Date: Mar 2008
Location: The Netherlands.
Posts: 506
Thanks: 11
Thanked 94 Times in 87 Posts
![]() |
That looks like an error in your spreadsheet. Make sure your spreadsheet is compatible with R; e.g. no missing entries, no spaces within cells, you dont copy an extra empty row, ect
__________________
The true ideals of great philosophies always seem to get lost somewhere along the road.. |
|
|
|
|
|
#5 |
|
Super Moderator
Join Date: Mar 2008
Location: The Netherlands.
Posts: 506
Thanks: 11
Thanked 94 Times in 87 Posts
![]() |
Also make sure the last thing you do before executing the read.table command is copy your data to the clipboard (crtl + c).. e.g. dont copy your data and then copy your command cause you lose the data... ect ect..
__________________
The true ideals of great philosophies always seem to get lost somewhere along the road.. |
|
|
|
|
|
#6 |
|
TS Contributor
Join Date: Sep 2008
Location: Australia
Posts: 488
Thanks: 26
Thanked 81 Times in 79 Posts
![]() |
thanks for the tip!
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
| Sponsored Links |
| Statistics Homework Help |