r brown-bag seminars : seminar-8

21
R Brown-bag seminar R Brown-bag seminar Session 8 Session 8

Upload: muhammad-nabi-ahmad

Post on 17-Jul-2015

574 views

Category:

Data & Analytics


0 download

TRANSCRIPT

R Brown-bag seminarR Brown-bag seminarSession 8Session 8

Summary Introduction Data Import (csv, txt ...) Data

Types Data-frames Question (sapply(tree,class) --ref(1) )

Basic Operations Help Summery Subset and Filter Duplicates and NA

Basic analysis/stats Graphs

Default package ggplot

How many have installed ggplot2 package Ref.1) http://www.statmethods.net/input/datatypes.html

Learn to Code &

Code to Learn

Tree <- read.table("datavis.csv",sep=",",header=T)

?separator ?Yes file has a Header

library(ggplot2)

RStudioFile → New File → R Script

ggplot(data=tree, aes(x=PosTopoSeq)) + geom_bar(stat="bin")

? ? ?Geometry = bar

statistical transformation = binbin = number of cases in group

Data frame Field on x

ggplot(data=tree, aes(x=VegStructure)) + geom_bar(stat="bin")

WOW!Shrubland

Some colours please

ggplot(data=tree, aes(x=VegStructure,colour=Site)) + geom_bar(stat="bin")

?Different colours for each site

ggplot(data=tree, aes(x=VegStructure,fill=Site)) + geom_bar(stat="bin")

Fill geometry

Veg. Structure = Shrubland is in all sites

&

Site 1 is richest in terms of

Veg. Structure

Question: Confirm that Shrubland is present in every site

ggplot(data=tree) + geom_boxplot(aes(Site,avTreeDen,col=Site))+ coord_flip() + facet_wrap(~VegStructure,ncol=1)

Yes Veg. Structure = Shrubland

is in all sites

ggplot(data=tree) + geom_point(aes(x=Carbon,y=Clay))

ggplot(data=tree,aes(x=Carbon,y=Clay))+geom_line() + geom_point()

ggplot(data=tree,aes(x=Carbon,y=Clay)) + geom_line(colour="red", linetype="dashed", size=0.5) +

geom_point(colour="red", size=2, shape=22, fill="red")

? linetype

0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash

what is shape = 25

ggplot(data=tree)+geom_point(aes(x=Carbon,y=Clay,col=Site))

ggplot(data=tree)+geom_line(aes(x=Carbon,y=Clay,col=Site))

gg <- ggplot() + geom_point(data=tree,aes(x=Carbon,y=Clay,col=Site)) + geom_line(data=tree,aes(x=Carbon,y=Clay,col=Site))

plot(gg)

ggplot(data=tree) + geom_boxplot(aes(Site, pH))

ggplot(data=tree) + geom_boxplot(aes(Site, Clay))

ggplot(data=tree) + geom_boxplot(aes(Site, Carbon))

What we have done today?

Coding

landscape portal example

Assignment

Write a program

− Load data− Show stats− Make graphs− Explain graphs

End