0% found this document useful (0 votes)
18 views8 pages

Assignment 1-Data Science

The document provides R commands to: 1) Create a dataframe from vectors of patient data including ID, weight, blood pressure, locality, smoking status, and tumour size. 2) Plot a graph showing the relationship between patient weight and blood pressure. Lines are added to separate data points by tumour size. 3) Create a stacked bar chart displaying the relationship between smoking status and tumour size to show their distributions. An alternative mosaic plot is also demonstrated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

Assignment 1-Data Science

The document provides R commands to: 1) Create a dataframe from vectors of patient data including ID, weight, blood pressure, locality, smoking status, and tumour size. 2) Plot a graph showing the relationship between patient weight and blood pressure. Lines are added to separate data points by tumour size. 3) Create a stacked bar chart displaying the relationship between smoking status and tumour size to show their distributions. An alternative mosaic plot is also demonstrated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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<-[Link](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<-[Link](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=[Link]="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="%",
[Link]=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