Adding different color points
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.3
df<-read.csv("https://raw.githubusercontent.com/tuyenhavan/Statistics/Dataset/LungCapData.csv",sep=";")
head(df)
## LungCap Age Height Smoke Gender Caesarean
## 1 6.475 6 62.1 no male no
## 2 10.125 18 74.7 yes female no
## 3 9.550 16 69.7 no female yes
## 4 11.125 14 71.0 no male no
## 5 4.800 5 56.9 no male no
## 6 6.225 11 58.7 no female no
# line plot
ggplot(data=df, aes(x=Age,y=LungCap,color=Gender)) + geom_point(aes(color=Gender)) + geom_line() + labs(y="Lung Capacity",x="Age")

Adding different color lines
ggplot(data=df, aes(x=Age,y=LungCap)) + geom_point(aes(color=Gender)) + geom_line(aes(color=Gender)) + labs(y="Lung Capacity",x="Age") + scale_color_hue(direction = -1)

Adding labels
ggplot(data=df, aes(x=Age,y=LungCap)) + geom_point(aes(color=Gender)) + geom_line(aes(color=Gender)) + labs(y="Lung Capacity",x="Age") + scale_color_hue(direction = -1) + geom_text(aes(label=Gender))

Barplot
ggplot(data=df,aes(x=Gender,fill=Smoke)) + geom_bar() # Stack

ggplot(data=df,aes(x=Gender,fill=Smoke)) + geom_bar(position = "dodge") # Side by side barplot

ggplot(data=df,aes(x=Gender,fill=Smoke)) + geom_bar(position = "fill",color="blue") # Stack barplot

ggplot(data=df,aes(x=LungCap,fill=Smoke)) + geom_density(alpha=0.2) # Density

ggplot(data=df,aes(x=LungCap,fill=Smoke)) + geom_density(position = "stack",aes(y=..count..),alpha=0.5)

Smooth_line
ggplot(data=df,aes(x=LungCap,y=Age)) + stat_smooth(geom="pointrange")
## `geom_smooth()` using method = 'loess'

polynomial function
ggplot(data=df,aes(x=LungCap,y=Age)) + stat_smooth(method = "lm",formula = y~poly(x,4))

Logistic regression
df$Los<-sample.int(2,nrow(df),replace = T)
df$Los<-as.factor(df$Los)
df$Los<-as.numeric(as.character(df$Los))
ggplot(data=df,aes(x=LungCap,y=Los)) + stat_smooth(method = "glm",family = binomial)
## Warning: Ignoring unknown parameters: family

Error Bar
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 3.3.3
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 3.3.3
## Loading required package: survival
## Warning: package 'survival' was built under R version 3.3.3
## Loading required package: Formula
## Warning: package 'Formula' was built under R version 3.3.3
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
ggplot(data=df,aes(x=Gender,y=LungCap)) + stat_summary(fun.y=mean,geom="bar",fill=c(2,4)) + stat_summary(fun.data = mean_cl_normal,geom = "errorbar")
