Mobile Phone Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 27 February 2013

Absolute beginners #RHelp

Posted on 04:12 by Unknown
R At the weekend I was thinking about posting here about how often, when I am trying to do simple things with R, I can't find the low level information I need, and that the online R communities are too high powered to give me help at the level I, and I'm sure others, need. I thought about calling for a new community to provide this sort of low level help.

Then I thought, f**k it, I'll do it myself.

RHelp




Click the graphs for larger version, copy and paste the code into R to try this for yourself.
Note: These are not real data, I made them up to show the method.

The anatomy of fish species depend on their diet. In a practical class, students examined two species of fish, mackerel (Scomber scombrus) and gurnard (Chelidonichthys cuculus). They made various measurements, including the standard length (from tip of snout to end of body) and the length of the intestine. The class pooled their data. There was a variation in the length of individual fish of each species, so the students calculated the ratio of the length of the intestine to the standard length of each fish. Using R:

> mackerel <- c(0.278, 0.389, 0.292, 0.268, 0.277, 0.364, 0.362, 0.217, 0.375, 0.338, 0.368)

> gurnard <- c(0.655, 0.702, 0.595, 0.667, 0.705, 0.687, 0.715, 0.656, 0.636, 0.701, NA)

> fish.data <- data.frame(cbind(mackerel, gurnard))

> attach(fish.data)

> summary(fish.data)
    mackerel         gurnard     
 Min.   :0.2170   Min.   :0.5950 
 1st Qu.:0.2775   1st Qu.:0.6552 
 Median :0.3380   Median :0.6770 
 Mean   :0.3207   Mean   :0.6719 
 3rd Qu.:0.3660   3rd Qu.:0.7017 
 Max.   :0.3890   Max.   :0.7150 
                  NA's   :1      

> boxplot(fish.data)

Boxplot

# This is a comment line - I can write notes here to remind me what I've done.
# Let's colour the graph in so that it's easier to see.
# What colours can R use?

> colors()
[1] "white" "aliceblue" "antiquewhite" "antiquewhite1" "antiquewhite2"
[6] "antiquewhite3" "antiquewhite4" "aquamarine" "aquamarine1" "aquamarine2"
#Edited - try it for yourself

# This is a scientific report, so don't use anything too bright.
# Why Should Engineers and Scientists Be Worried About Color?
# http://www.research.ibm.com/people/l/lloydt/color/color.HTM
# But don't spend too long playing with colours :-)
# This might help:
# http://research.stowers-institute.org/efg/R/Color/Chart/

> boxplot(fish.data, col="slategray2")

# This graph needs tidying up for presentation:

> boxplot(fish.data, ylab="Standard length : Intestine ratio", main="Graph of standard length to intestine length ratio", col="slategray2")

Boxplot

# Well they look different.
# We could do statistical tests to see if they really are.
# But this post is about data visualization.

> stripchart(fish.data)

Stripchart

#Come on R, you can do better than that.

> ?stripchart

> stripchart(fish.data, vertical=TRUE)

# Better.

> stripchart(fish.data, vertical=TRUE,method="jitter")

# Even better

> stripchart(fish.data, vertical=TRUE,method="jitter", pch=c(1, 2), main="Plots of standard length to intestine length ratio", ylab="Standard length : Intestine ratio")

Stripchart

# You can have more than one graph window open at a time if you want:
# windows()    on Windows OS
# quartz()     on Macintosh OS
# I'd also like to plot this data as a barplot with standard deviation error bars to show the variation in the data.

> summary(fish.data)
    mackerel         gurnard    
 Min.   :0.2170   Min.   :0.5950
 1st Qu.:0.2775   1st Qu.:0.6552
 Median :0.3380   Median :0.6770
 Mean   :0.3207   Mean   :0.6719
 3rd Qu.:0.3660   3rd Qu.:0.7017
 Max.   :0.3890   Max.   :0.7150
                  NA's   :1     

# Make a file of the mean values to plot:

> means <- c(0.3207, 0.6719)

# Calculate the standard deviations for the error bars:

> sd(mackerel, na.rm=TRUE)
[1] 0.05640761

> sd(gurnard, na.rm=TRUE)
[1] 0.03756313

# Make a file to plot the error bars:

> error.bars <- c(0.05640761, 0.03756313)

> SD.graph <- barplot(means, ylim=c(0,max(means)+max(error.bars)))

# This plots the graph. The y-axis scale will depend on the size of the longest error bar. You can change it by setting a value of ylim

> arrows(SD.graph, means-error.bars, SD.graph, means+error.bars, code=3, angle=90, length=.1)

# This adds the error bars
# Now a decent version for presentation:

> SD.graph <- barplot(means, main="Means of standard length to intestine length ratio", names.arg=c("Mackerel", "Gurnard"), ylab="Standard length : Intestine ratio", ylim=c(0,max(means)+max(error.bars)))

> arrows(SD.graph, means-error.bars, SD.graph, means+error.bars, code=3, angle=90, length=.1)

Barplot





A.J. Cann
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in R, RHelp, Science, visualization | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Student feedback using Google+
    Whether or not you take a constructivist view of education, feedback on performance is inevitably seen as a crucial component of the proces...
  • An Introduction to Teaching With Social Media #cll1213
    Tomorrow I'm off to: Changing the Learning Landscape – The Use of Social Media in Science and Technology Teaching and Learning ( #cll12...
  • Positive academic outcomes of Facebook use
    Chan, C.L., Fu, W.E., Lai, K.R., and  Tseng, S.F. (2013) Feasibility study of using social networks platform for learning support: an exampl...
  • Certifiable
    A.J. Cann
  • The Information
    Among my holiday reading was James Gleick's The Information . Blurb: " a chronicle that shows how information has become the moder...
  • Biology Open Educational Resources
    The Society of Biology has launched a new website which aims to identify, collect and promote existing bioscience open educational resource...
  • The WordPress.com Reader
    I'm still pretty happy with The Old Reader , apart from the inability to organize feeds in folders and lingering concerns about the sus...
  • Why Good Classes Fail
    "The problem of why good classes fail has become a bit of an obsession for me lately. I visit several colleges and universities every s...
  • Why I didn't sign up for #oldsmooc
    I would like to have signed up for the OU's learning design MOOC , but I have a list of reasons why I didn't: I'm trying to be ...
  • Learning Outcomes - the wrong way round
    Martin Weller was questioning the value of learning outcomes on Twitter this morning, asking whether anyone ever reads them, and noting:...

Categories

  • 2b2k
  • Aggregation
  • alt-c
  • altmetrics
  • AoB
  • Art
  • Assessment
  • Attention
  • BeyondGoogle
  • Biology
  • BioSET
  • Blackboard
  • Blogging
  • Books
  • Careers
  • Checklists
  • Conference
  • Connectivity
  • Copyright
  • Curation
  • DarkSocial
  • digilit
  • distance learning
  • Economics
  • Education
  • Engagement
  • Environment
  • Facebook
  • Feedback
  • FriendFeed
  • Futurology
  • Genetics
  • Google
  • Google+
  • Higher Education
  • History
  • Humour
  • IDontHaveATagForThis
  • Impact
  • iPad
  • JISC
  • Leicester
  • Library
  • Life
  • Links
  • Marketing
  • Maths
  • Media
  • Medicine
  • Mobile
  • MOOC
  • Music
  • OER
  • Open Access
  • Open Peer Review
  • Open Science
  • Photography
  • Plagiarism
  • PLE
  • PLN
  • Podcast
  • Politics
  • Postgraduate
  • Publishing
  • QRcode
  • R
  • Recipe
  • REF
  • Reflection
  • Research
  • RHelp
  • RSS
  • Science
  • SmallWorlds
  • SOAR
  • Social Networks
  • Sport
  • Statistics
  • Tagging
  • Technology
  • VandR
  • Video
  • visualization
  • Web 3.0
  • wiki
  • Writing
  • Xerte

Blog Archive

  • ▼  2013 (204)
    • ►  November (15)
    • ►  October (19)
    • ►  September (11)
    • ►  August (15)
    • ►  July (14)
    • ►  June (25)
    • ►  May (25)
    • ►  April (20)
    • ►  March (15)
    • ▼  February (25)
      • Developing Techniques for Pedagogical Research in ...
      • Absolute beginners #RHelp
      • Practical digilit 101
      • Evidence and emotion
      • The Great Ink Ripoff
      • The value of formative assessment
      • The strong get stronger and the weak .... don't
      • Writing
      • Does technology enhance learning?
      • In competiton with the pendulum
      • Brainwashed into the cult of social media
      • Positive academic outcomes of Facebook use
      • Lessons in Life
      • It's contagious
      • A Dangerously Radical Suggestion?
      • Changing the Learning Landscape #cll1213
      • Big Fat Turnitin Grademark #Fail ?
      • Sadly, Word Verification is Back
      • Your weekend reading assignment
      • More evidence on the Dark Social pile
      • The curation problem in science education
      • Let your creative juices flow
      • Richard the Turd
      • Dear students...
      • So it goes with God
    • ►  January (20)
  • ►  2012 (259)
    • ►  December (13)
    • ►  November (29)
    • ►  October (25)
    • ►  September (18)
    • ►  August (14)
    • ►  July (26)
    • ►  June (32)
    • ►  May (23)
    • ►  April (16)
    • ►  March (25)
    • ►  February (21)
    • ►  January (17)
  • ►  2011 (37)
    • ►  December (16)
    • ►  November (20)
    • ►  October (1)
Powered by Blogger.

About Me

Unknown
View my complete profile