R seminar series - part 6

Last update on March 12, 2015.

Sixth seminar of "R brown-bag seminars" was held in ICRAF today.  Leigh Winowiecki (PhD, Soil Scientist, CIAT) presented  "Introduction to ggplot"  topic. Presentation of today's seminar is available here.

Data used in this seminar is available here and source code from seminar 6 is shown below:


#Leigh Winowiecki
#ICRAF Training March 12, 2015
#load dataset
 
tree<-read.table("datavis.csv",sep=",",header=T)
head(tree)
summary(tree)
str(tree)
 
#load ggplot package
library(ggplot2)
 
#Lets plot Clay by Carbon
#First Graphic
ggplot(data=tree)+geom_point(aes(x=Carbon,y=Clay))
 
#Second Graphic- add the color of Site
ggplot(data=tree)+geom_point(aes(x=Carbon,y=Clay,col=Site))
 
#Third Graphic- add faceting of VegStructure
ggplot(data=tree)+geom_point(aes(x=Carbon,y=Clay,col=Site))+facet_wrap(~VegStructure,ncol=1)
 
#Fourth Graphic- add xaxis and yaxis labels and move legend title
ggplot(data=tree)+geom_point(aes(x=Carbon,y=Clay,col=Site))+facet_wrap(~VegStructure,ncol=1)+theme(legend.position="top")+ xlab("Carbon (%)")+ylab("Clay (%)")
 
#Now lets make a few graphics using geom_boxplot
ggplot(data=tree) + geom_boxplot(aes(Site,avTreeDen))
 
# Add Site color
ggplot(data=tree) + geom_boxplot(aes(Site,avTreeDen,col=Site))
 
#Flip the coord
ggplot(data=tree) + geom_boxplot(aes(Site,avTreeDen,col=Site))+ coord_flip()
 
#4 Add faceting by Veg Structure
ggplot(data=tree) + geom_boxplot(aes(Site,avTreeDen,col=Site))+ coord_flip()+facet_wrap(~VegStructure,ncol=1)
 
#final1
ggplot(data=tree) + geom_boxplot(aes(Site,avTreeDen,col=Site)) + ylab(expression(paste('Tree Density (tree ',ha^{-1},')')))+ xlab("")+ coord_flip()+facet_wrap(~~VegStructure,ncol=1)+scale_colour_discrete(name="Site Name")
Note: Due to slow internet speed, it is not possible to install R packages and cover seminar material. Thus all participants should install required R packages before coming to the next seminar. Please also download required data files as well.  

Next entry

Previous entry

Related entries

Similar entries

Pingbacks

Pingbacks are closed.

Comments

No comments yet.

Post your comment