library(readr)
birthwt <- read_csv("birthwt.csv")
expd <- read_csv("healthexp.csv")
library(ggplot2)
ggplot(data = birthwt,aes(x=low))+geom_bar()
ggplot(data = birthwt,aes(x=age))+geom_bar()
ggplot(data = birthwt,aes(x=age))+geom_bar(fill="aquamarine4")
In the above code, we are using the fill attribute in the geom_bar() function to give the bar plot a color.
Bar-plot( Variation in terms of proportion)
ggplot(data = birthwt,aes(x=low,fill=factor(race)))+geom_bar(position = "fill")
ggplot(data = birthwt,aes(x=age,fill=factor(low)))+geom_bar(position = "dodge")
a <- ggplot(expd,aes(x=RACE))
a + geom_bar() + theme_bw() + labs(x="Race of Insured", y="Frequency", title="Distribution of Race of Insured")
b <- ggplot(expd,aes(x=REGION,fill=RACE))
b + geom_bar() + theme_grey() + labs(x="Region", y="Frequency", title="Region by Race of Insured")
c <- ggplot(expd,aes(x=RACE,fill=EDUC))
c + facet_wrap(~REGION) + geom_bar() + theme_grey() + labs(x="Region", y="Frequency", title="Race by Education by Region")
d <- ggplot(expd,aes(x=AGE,y=EXPENDOP))
d + geom_point() + theme_light() + labs(x="Age", y="Expenditures for outpatient visits", title="Outpatient Expenditures")
e <- ggplot(expd,aes(x=AGE))
e + geom_histogram(binwidth=7) + theme_light() + labs(x="Insured Age (bandwith=7)", y="Insured Count", title="Distribution of Age")
f <- ggplot(expd,aes(x=AGE,fill=EDUC))
f + geom_histogram(binwidth=7) + theme_light() + labs(x="Insured Age (bandwith=7", y="Insured Count",
title="Distribution of Age by Education")
g <- ggplot(expd,aes(x=REGION,y=AGE))
g + geom_boxplot() + theme_bw() + labs(x="Region", y="Age",
title="Distribution of Age by Region")
h <- ggplot(expd,aes(x=REGION,y=AGE,color=EDUC))
h + geom_boxplot() + coord_flip() + theme_bw() + labs(x="Region", y="Age", title="Distribution of Age by Region")