## 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

summary(tree)
str(tree)

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))

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.

### Pingbacks

Pingbacks are closed.