Statistics Help @ Talk Stats Forum

Go Back   Statistics Help @ Talk Stats Forum > Statistical Software > R/Splus

[Statistics Help]
Reply
 
Thread Tools Search this Thread Display Modes
Old 10-19-2009, 02:44 AM   #1
bugman
Senior Member
 
Join Date: Sep 2008
Location: Australia
Posts: 228
Thanks: 22
Thanked 35 Times in 35 Posts
bugman is on a distinguished road
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 03:58 AM. Reason: Removed errors from script, bugman what version of R r u using?
bugman is offline   Reply With Quote
Old 10-19-2009, 04:10 AM   #2
TheEcologist
TS Contributor
 
TheEcologist's Avatar
 
Join Date: Mar 2008
Location: The Netherlands.
Posts: 401
Thanks: 7
Thanked 71 Times in 65 Posts
TheEcologist is on a distinguished road
Quote:
Originally Posted by bugman View Post
I am having trouble finishing a level plot in R.

A) plot the y axis with the Column names and xaxis with the row names
B) place the color key under the xaxis.
Your code already did A, though I dont really see why you need the axis command.

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:
Originally Posted by bugman View Post
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.
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")))
__________________
The true ideals of great philosophies always seem to get lost somewhere along the road..
TheEcologist is offline   Reply With Quote
The Following User Says Thank You to TheEcologist For This Useful Post:
bugman (10-19-2009)
Old 10-19-2009, 11:26 PM   #3
bugman
Senior Member
 
Join Date: Sep 2008
Location: Australia
Posts: 228
Thanks: 22
Thanked 35 Times in 35 Posts
bugman is on a distinguished road
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'

#################
bugman is offline   Reply With Quote
Old 10-20-2009, 03:15 AM   #4
TheEcologist
TS Contributor
 
TheEcologist's Avatar
 
Join Date: Mar 2008
Location: The Netherlands.
Posts: 401
Thanks: 7
Thanked 71 Times in 65 Posts
TheEcologist is on a distinguished road
Quote:
Originally Posted by bugman View Post
Thanks for this!
#######
In read.table("clipboard") :
incomplete final line found by readTableHeader on 'clipboard'
#################
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..
TheEcologist is offline   Reply With Quote
Old 10-27-2009, 05:00 AM   #5
TheEcologist
TS Contributor
 
TheEcologist's Avatar
 
Join Date: Mar 2008
Location: The Netherlands.
Posts: 401
Thanks: 7
Thanked 71 Times in 65 Posts
TheEcologist is on a distinguished road
Quote:
Originally Posted by bugman View Post
Thanks for this!
#######
In read.table("clipboard") :
incomplete final line found by readTableHeader on 'clipboard'

#################
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..
TheEcologist is offline   Reply With Quote
Old 10-27-2009, 07:06 PM   #6
bugman
Senior Member
 
Join Date: Sep 2008
Location: Australia
Posts: 228
Thanks: 22
Thanked 35 Times in 35 Posts
bugman is on a distinguished road
Thumbs up

thanks for the tip!
bugman is offline   Reply With Quote
Reply











Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -5. The time now is 05:10 PM.





Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2005-2009, TalkStats.com

Get free statistics help or just hang out and talk about statistics!

Sponsored Links
Statistics Homework Help - Full Time Trader - Work At Home - Priceline Winning Bids