library(ggplot2)
library(gcookbook)
p <- ggplot(heightweight, aes(x=ageYear, y=heightIn))+ geom_point()
p + ggtitle("Age and Height of
Schoolchildren")

p + ggtitle("Age and Height\nof
Schoolchildren")

p <- ggplot(heightweight, aes(x=ageYear, y=heightIn))+ geom_point()
p + labs (title = "Age and Height\nof School Children" )

p + ggtitle("Age and Height of School
Children") + theme(plot.title=element_text(hjust = 0.5))

p <- ggplot(heightweight,aes(x=ageYear, y=heightIn)) + geom_point()
p + theme(axis.title.x=element_text(size
=16, lineheight=.9, family="Times", face
="bold.italic", colour="red"))
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
## not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

p <- ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
p + annotate("text", x=15, y=53, label="Some text", size = 7, family="Times",
fontface="bold.italic", colour="red")
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

p + geom_text(aes(label=weightLb), size=4,
family="Times", colour="red")
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

p <- ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
p

p + theme_grey(base_size=16, base_family= "Times")
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
## not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

p + theme(
panel.grid.major = element_line(colour="red"),
panel.grid.minor = element_line(colour="red", linetype="dashed",size=0.2),
panel.background = element_rect(fill="lightblue"),
panel.border = element_rect(colour="blue", fill=NA, linewidth =2))
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

p + ggtitle("Title") +
theme(axis.title.x = element_text(colour="green", size=14),
axis.text.x = element_text(colour="blue"),
axis.title.y = element_text(colour="red", size=14, angle = 90),
axis.text.y = element_text(colour="yellow"),
plot.title = element_text(colour="purple", size=20, face="bold"))

mytheme <- theme_bw() + theme(text =element_text(colour="red"),
axis.title = element_text(size = rel(1.25)))
p <- ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
p + mytheme

p <- ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

p + theme(panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank())

p + theme(panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank())

p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()
p

p + guides(fill="none")

p + scale_fill_discrete(guide=FALSE)
## Warning: The `guide` argument in `scale_*()` cannot be `FALSE`. This was deprecated in
## ggplot2 3.3.4.
## ℹ Please use "none" instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot() + scale_fill_brewer(palette="Pastel2")
p + theme(legend.position="top")

p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group))+ geom_boxplot()
p + scale_fill_grey(start=.5, end=1, limits=
c("trt1", "trt2", "ctrl"))

p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()
p

p + guides(fill=guide_legend(reverse=TRUE
))

p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()
p + labs(fill="Condition")

p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()
p + scale_fill_discrete(labels=c("Control", "Treatment 1", "Treatment 2"))

library(gcookbook)
hw <- ggplot(heightweight, aes(x=ageYear, y=heightIn, colour=sex)) +geom_point(aes(
size=weightLb)) + scale_size_continuous(range=c(1,4))
hw

hw + labs(colour="Male/Female", size="Weight/n(pounds")

p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()
p + theme(legend.text=element_text(face="italic", family="Times", colour="red",
size=14))
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
## not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
