In this set of exercises we will use lattice package. Firstly, we have to install this package with command install.packages(“lattice”) and then we will call it library(lattice) . Lattice package permits us to create univariate, bivariate and trivariate plots. For this set of exercises we will see trivariate plots. We will use a dataset example […]

## Lattice exercises – part 2 solutions

Below are the solutions to these exercises on lattice plots. ############### # # # Exercise 1 # # # ############### library(lattice) dataset <- read.csv("C:/Users/matt6/Desktop/author kit/Nuova cartella/dataset.csv", sep=";") attach(dataset) levelplot(win ~ gd*gs|team,dataset,xlab="Goals done",ylab="Goals received") ############### # # # Exercise 2 # # # ############### contourplot(win ~ gd*gs|team,dataset,xlab="Goals done",ylab="Goals received",region=F) contourplot(win ~ gd*gs|team,dataset,xlab="Goals done",ylab="Goals received",region=T) ############### # […]

## Lattice exercises – part 1

In the exercises below we will use the lattice package. First, we have to install this package with install.packages(“lattice”) and then we will call it library(lattice) . The Lattice package permits us to create univariate, bivariate and trivariate plots. For this set of exercises we will see univariate and bivariate plots. We will use a […]

## Lattice part 1 solutions

Below are the solutions to these exercises on lattice. ############### # # # Exercise 1 # # # ############### library(lattice) dataset <- read.csv("http://www.r-exercises.com/wp-content/uploads/2016/04/dataset.csv", sep=";") attach(dataset) barchart(gd ~ win |team,groups=team,xlab="Goals",box.ratio=2,horizontal=F,auto.key=list(space="top", columns=2, title="Team", cex.title=1)) ############### # # # Exercise 2 # # # ############### Team1<-subset(dataset,team==1) Team2<-subset(dataset,team==2) bwplot(Team1$gs,col=2) bwplot(Team2$gs,col=4) ############### # # # Exercise 3 # # # […]

## 3D plotting exercises

In this set of exercises we will introduce the concept of 3D plotting. Specifically, we will use these commands:image(), contour() and persp(). For these exercises, you need to have a basic understanding of R objects and functions, in particular some knowledge about matrix . This set is the fourth set of exercises is a series […]

## 3d plotting solutions

Below are the solutions to these exercises on 3D plots. ############### # # # Exercise 1 # # # ############### m <- matrix(runif(100),10,10) image(m) ############### # # # Exercise 2 # # # ############### m <- matrix(runif(100),10,10) image(m, axes = FALSE, col = grey(seq(0, 1, length = 256)),oldstyle=T) ############### # # # Exercise 3 # […]

## Graphics parameters exercises

In the exercises below we practice how to personalize graphics parameters, how to produce different plots at the same time and how to save a plot in a file. We will use commands such as par and jpeg. We will use the mtcars dataset, provided by R Cran (we can upload the dataset by typing […]

## Graphics parameters solutions

Below are the solutions to these exercises on graphics parameters. ############### # # # Exercise 1 # # # ############### attach(mtcars) par(col=2,lty=2,bg=4);plot(mpg,wt) ############### ############### # # # Exercise 2 # # # ############### par(mfrow=c(2,1));plot(mpg,wt);plot(mpg,hp) ############### # # # Exercise 3 # # # ############### par(mfrow=c(2,2)) plot(mpg,wt,col=2,xlab="Weight",ylab="Miles per Gallon", main="Mpg vs Weight") plot(mpg,hp,col=3,xlab="Horse Power",ylab="Miles per Gallon", […]

## Customize a scatterplot exercises

In the following exercises we practice how to customize a scatterplot. We will use axis , to add an axis; mtext to add a text; and legend to add a legend. Moreover we practice how to add details in every stage. We will use the mtcars dataset, provided by R Cran (we can upload dataset […]

## customize scatterplot solutions

Below are the solutions to these exercises on how to customize a scatterplot. ############### # # # Exercise 1 # # # ############### attach(mtcars) plot(mpg,drat,xlab=”Miles per gallon”) ############### # # # Exercise 2 # # # ############### plot(mpg,drat,xlab=”Miles per gallon”,ylab=”Rear axle ratio”) plot(mpg,drat,xlab=”Miles per gallon”,ylab=”Rear axle ratio”,xlim=c(0,30),col=2,lwd=2,ylim=c(0,7)) ############### # # # Exercise 3 # # […]