Title
#labs (title = '', x = '', y ='')
#theme (plot.title = element_text (color = '', size =..., face = 'bold', hjust = 0.5))
#theme (plot. subtitle = ....)
#theme (plot. caption = ....)
#Arguments for fucntion element_text:
# + face: plain, italic, bold.italic
# + hjust: horizontal justification, in [0,1]
# + vjust= vertical justification, in [0,1]
Plots - Example - Title
library(ggplot2)
data("ToothGrowth")
attach(ToothGrowth)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
ggplot(ToothGrowth, aes(x= dose, y = len)) + geom_boxplot() +
labs (title = 'boxplot', x = 'dose', y = 'length',
subtitle = '08/14/2018', caption = 'by Ly Tran') +
theme (plot.title = element_text(color = 'blue', size = 14, face = 'bold',hjust=0.5)) +
theme (plot.subtitle = element_text(color = 'red',hjust = 1)) +
theme (plot.caption = element_text(color = 'orange', size = 10, face = 'italic'))

ggplot(ToothGrowth, aes(x= dose, y = len, fill = dose)) +
geom_boxplot() +
labs (title = 'boxplot', x = 'dose', y = 'length', fill = 'dose_categories')

Lines
#linetype = 'dashed', 'solid'; 'longdash'
Lines - Example
df <- data.frame(time=c("breakfeast", "Lunch", "Dinner"),
bill=c(10, 30, 15,5,20,30),
sex = rep(c("Female", "Male"), each =3))
head(df)
## time bill sex
## 1 breakfeast 10 Female
## 2 Lunch 30 Female
## 3 Dinner 15 Female
## 4 breakfeast 5 Male
## 5 Lunch 20 Male
## 6 Dinner 30 Male
#1 line with 1 group
ggplot(df, aes(x= time, y = bill, group = 1)) +
geom_line(linetype = "dashed") +
geom_point() +
labs (title = 'line', x = 'bill', y = 'bill')

#Multiple lines with multiple groups
ggplot(df, aes(x= time, y = bill, group = sex)) +
geom_line(linetype = "dashed", col = 'red') +
geom_point(color = 'blue') +
labs (title = 'line', x = 'bill', y = 'bill')

#Changes line types + color automatically based on different groups
ggplot(df, aes(x= time, y = bill, group = sex)) +
geom_line(aes(linetype = sex, col = sex)) +
geom_point(aes(color = sex)) +
labs (title = 'line', x = 'bill', y = 'bill') +
theme(legend.position = "top")

#If we want to change linetypes and color manually, use scale_color_manual() + scale_linetype_manual()
ggplot(df, aes(x= time, y = bill, group = sex)) +
geom_line(aes(linetype = sex, col = sex)) +
geom_point(aes(color = sex)) +
scale_linetype_manual(values = c ("twodash", "dotted")) +
scale_color_manual(values = c ('pink', 'blue')) +
labs (title = 'line', x = 'bill', y = 'bill') + theme(legend.position = "top")
