You are on page 1of 8

Assignment 1

Datascience

1)Please write the command to create dataframe in R.


id<-c(1,2,3,4,5,6,7)
weight<-c(20,27,24,22,23,25,28)
bp<-c(140,130,120,134,100,116,143)
locality<-c("urban","rural","urban","urban","rural","rural","urban")
smoking<-c("no","yes","no","yes","yes","no","yes")
tumour<-c("small","small","large","small","large","small","large")
healthdata<-data.frame(id,weight,bp,locality,smoking,tumour)
healthdata
attach(healthdata)
#console
>id<-c(1,2,3,4,5,6,7)
> weight<-c(20,27,24,22,23,25,28)
> bp<-c(140,130,120,134,100,116,143)
> locality<-c("urban","rural","urban","urban","rural","rural","urban")
> smoking<-c("no","yes","no","yes","yes","no","yes")
> tumour<-c("small","small","large","small","large","small","large")
> healthdata<-data.frame(id,weight,bp,locality,smoking,tumour)
> healthdata
id weight bp locality smoking tumour
1 1 20 140 urban no small
2 2 27 130 rural yes small
3 3 24 120 urban no large
4 4 22 134 urban yes small
5 5 23 100 rural yes large
6 6 25 116 rural no small
7 7 28 143 urban yes large
> attach(healthdata)
The following objects are masked _by_ .GlobalEnv:

bp, id, locality, smoking, tumour, weight

The following objects are masked from healthdata (pos = 3):

bp, id, locality, smoking, tumour, weight

2) Please write the command for plotting the graph between weight and bloodpressure

plot(weight,bp,
main="WEIGHT VS BLOODPRESSURE",
sub="relation between weight and bloodpressure",
col="black",
pch=25)
R consists of hard coding,moderate coding
and has gui based interface which is called r
commander
1)cex->size of text
2)pos->position
3)c->colour
text(weight,bp,cex=0.6,pos=1,col="black")
text(weight,bp,locality,cex=0.9,pos=2,col="r
ed")
text(wight,bp,weight,cex=0.7,pos=3,col="blu
e")
text(weight,bp,bp,cex=0.6,pos=4.col="green"
)
plot(bp~weight)
points(bp[tumour=="small"]~weight[tumour=="small"],
main="weight vs. bp",
xlab="weight",ylab="bp",col="black",pch=16)
points(bp[tumour=="large"]~weight[tumour=="large"],
main="weight vs. bp",
xlab="weight",ylab="bp",col="red",pch=24)

#saperate regression line


abline(lm(bp~weight))
abline(lm(bp[tumour=="small"]~bp[tumour=="small"]),col="pink")
abline(lm(bp[tumour=="large"]~bp[tumour=="large"]),col="violet")

3)Please write the command for creating stacked chart between smoking
and tumour
counts<-table(smoking,tumour)
counts

barplot(counts,
main="stacked chart of smoking and tumour",
xlab="smoking",
ylab="%",
names.arg=c("large","small"),col=c("pink","skyblue"),
legend=rownames(counts),space=1,beside=F)

grid()
mosaicplot(counts,col=c("pink","lightgreen"))

You might also like