0% found this document useful (0 votes)
4 views2 pages

Yearly Data Command

The document contains R code for analyzing and visualizing yearly data from 2010 to 2016 for various health indicators in Riau Province, specifically focusing on Pekanbaru District. It includes data loading, descriptive statistics, and multiple plots to illustrate fluctuations in CDR, CNR, ATTDR, and POSR over the specified years. The visualizations are created using both lattice and base R plotting functions, highlighting trends and comparisons among the indicators.

Uploaded by

suyantounri2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Yearly Data Command

The document contains R code for analyzing and visualizing yearly data from 2010 to 2016 for various health indicators in Riau Province, specifically focusing on Pekanbaru District. It includes data loading, descriptive statistics, and multiple plots to illustrate fluctuations in CDR, CNR, ATTDR, and POSR over the specified years. The visualizations are created using both lattice and base R plotting functions, highlighting trends and comparisons among the indicators.

Uploaded by

suyantounri2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

library(lattice)

library(ggplot2)
library(epicalc)
zap()
setwd("D:/QE DATA")
[Link]<- [Link]("YEARLY [Link]")
use([Link])
head([Link])
des([Link])
class([Link])
[Link]
des([Link])
head([Link])
xyplot(CDR~YEAR|DIST, data = [Link], type="l",main=" The Yearly Fluctuation of
CDR over 2010 - 2016\ in each district in Riau Province")
xyplot(CNR~YEAR|DIST, data = [Link], type="l",main="The Yearly Fluctuation of CNR
over 2010 - 2016\ in each district in Riau Province")
xyplot(ATTDR~YEAR|DIST, data = [Link], type="l",main="The Yearly Fluctuation of
ATTDR over 2010 - 2016\ in each district in Riau Province")
xyplot(POSR~YEAR|DIST, data = [Link], type="l",main="The Yearly Fluctuation of
POSR over 2010 - 2016\ in each district in Riau Province")
xyplot(POP~YEAR|DIST, data = [Link], type="l",main="Trend of Population number
over 2010 - 2016 in each district in Riau")
###################################################################################
###########

keepData(subset = DIST=="Pekanbaru")
plot(YEAR,CDR,type="l",pch=0,lty=2,col="blue", xlab = "", ylab="", main="The yearly
fluctuation of CDR\
in Pekanbaru District, Riau Province from 2010 to 2016")
plot(YEAR,CNR,type="b",pch=0,lty=2,col="blue", xlab = "", ylab="", main="The yearly
fluctuation of CNR\
in Pekanbaru District, Riau Province \from 2010 to 2016")
plot(YEAR,ATTDR,type="b",pch=0,lty=2,col="blue", xlab = "", ylab="", main="The
yearly fluctuation of ATTDR\
in Pekanbaru District, Riau Province \from 2010 to 2016")
plot(YEAR,POSR,type="b",pch=0,lty=2,col="blue", xlab = "", ylab="", main="The
yearly fluctuation of POSR\
in Pekanbaru District, Riau Province \from 2010 to 2016")

## add extra space to right margin of plot within frame


opar<-par([Link] = TRUE)
par(mar=c(5, 4, 4, 6) + 0.1)
## Plot first set of data and draw its axis
plot(YEAR,CDR,type="b",pch=15,lty=2,col="blue", xlab = "", ylab="", xlim= c
(2010,2016),ylim= c(0,100),main="The yearly fluctuation of TB reports\
in Pekanbaru District, Riau Province from 2010 to 2016")
mtext("%",side=2,line=2.5)
box()

#############################
opar<-par([Link] = TRUE)
par(lwd=2, cex=0.5, [Link]=2)
par(mar=c(5, 4, 4, 6) + 0.1)
plot(YEAR,CDR,type="b",pch=15,lty=2,col="blue", xlab = "year", ylab="%", xlim= c
(2010,2016),ylim= c(0,100),main="The yearly fluctuation of TB reports\
in Pekanbaru District, Riau Province from 2010 to 2016")
abline(h=c(70), lwd=1.5, lty=2, col="blue")
par(new=TRUE)
plot( YEAR, CNR, type="l", pch=15, xlab="", ylab="", axes= FALSE,col="green" )
axis(4, ylim=c(50,200), col="red",[Link]="black",las=1)
abline(h=c(70), lwd=1, lty=2, col="blue")
abline(v=c(2014,2015), lwd=2, lty=1, col="grey")
legend("topleft", inset = .05, title= "TB reports", c("CDR","CNR"),
lty=c(1,2,3), pch=c(15,15,15), col=c("blue", "green", "red"))
par(opar)
lines(YEAR,ATTDR, type="l", pch=17,lty=2,col="green")
lines(YEAR,POSR, type="l", pch=17, lty=2,col="purple")
abline(h=c(70), lwd=1.5, lty=2, col="blue")
abline(h=c(15), lwd=1, lty=2, col="purple")
#Allow a second plot on the same graph
par(new=TRUE)
## Plot the second plot and put axis scale on right
plot( YEAR, CNR, type="l", pch=15, xlab="", ylab="", axes= FALSE,col="red" )
## a little farther out (line=4) to make room for labels
mtext("per 100000 population",side=4,col="red",line=4)
axis(4, ylim=c(50,200), col="red",[Link]="red",las=1)
abline(v=c(2014,2015), lwd=2, lty=1, col="black")
abline(v=c(128), lwd=1,lty=1,col="red")
## Draw the time axis
axis(1,pretty(range(time),10))
mtext("YEAR",side=1,col="black",line=2.5)
## Add Legend
legend ("topleft", inset = .05, title= "TB reports", c("CDR","ATTDR","POSR","CNR"),
lty=c(1,2,3,4), pch=c(15,15,15,15), col=c("blue", "green","purple" ,"red"))
par(opar)

You might also like