Runhang Shu

Visualize Your Data(1)

Runhang / 2019-03-24


data<-read.csv("primates data.csv")
data ## When we look at this data, we can see there are a lot of NA and we want to get rid of them
##              Spp Bodywt Brainwt
## 1   Potar monkey   10.0     115
## 2        Gorilla  207.0     406
## 3          Human   62.0    1320
## 4  Rhesus monkey    6.8     179
## 5          Chimp   52.2     440
## 6                    NA      NA
## 7                    NA      NA
## 8                    NA      NA
## 9                    NA      NA
## 10                   NA      NA
## 11                   NA      NA
## 12                   NA      NA
## 13                   NA      NA

vec=is.na(data$Brainwt) ## create a vector to manipulate data-- it is very useful
newdata<-data[!vec,] ## the exclamatory mark "!"" mean "reverse", that means we do not want rows that contain NA. 
newdata 
##             Spp Bodywt Brainwt
## 1  Potar monkey   10.0     115
## 2       Gorilla  207.0     406
## 3         Human   62.0    1320
## 4 Rhesus monkey    6.8     179
## 5         Chimp   52.2     440

Now, we get rid of the data we do not want and let us plot our data!

plot(x=newdata$Bodywt,y=newdata$Brainwt,pch=19,xlab='Body weight(kg)',ylab='Brain weight(kg)',xlim=c(0,250))
## pch is use for different type of dot, xlab set the x-axis text,xlim set the x-axis length
## Now we want to add text alongside each dot 
text(x=newdata$Bodywt,y=newdata$Brainwt,labels=newdata$Spp,pos=4)


## pos=4 means "right", pos=1 means "under"