Ref: ggplot2 title : main, axis and legend titles
Ref: ggplot2 标题居中
Ref:
Ref:
Ref:
Example: theme(plot.title = element_text(color="red", size=14, face="bold.italic"))
# Default plot
p <- ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot() +
ggtitle("Plot of length \n by dose") +
xlab("Dose (mg)") + ylab("Teeth length")
p
# Change the color, the size and the face of
# the main title, x and y axis labels
p + theme(
plot.title = element_text(color="red", size=14, face="bold.italic"),
axis.title.x = element_text(color="blue", size=14, face="bold"),
axis.title.y = element_text(color="#993333", size=14, face="bold")
)
Example: theme(plot.title = element_text(hjust = 0.5))
library(ggplot2)
ggplot(data=mtcars, aes(x=wt, y=mpg)) +
geom_point() +
labs(title="Automobile Data", x="Weight", y="Miles Per Gallon")+
theme(plot.title = element_text(hjust = 0.5)) #也就加上这一行
Example: