ggplot2 - 图片的各种标题
2019-12-16 本文已影响0人
吴十三和小可爱的札记
ggplot2的labs是一个定义各种label 的总函数,可以用于定义各种图片中的标题类型。
各种标题
title:
subtitle:
caption:右下方的补充说明
tag:右上方的标签。
x:x轴名字
y:y轴名字
require(tidyverse)
data <- diamonds %>%
sample_n(1000)
ggplot(data = data) +
geom_point(aes(x = carat, y = price, color =price))+
labs(title = "This is title",
subtitle = "This is subtitle",
caption = "This is caption",
tag = "This is a tag",
x = "new x label",
y = "New y label")

legend 相关
包括外周颜色、填充颜色、形状、标签名字等。
ggplot(data = data) +
geom_point(aes(x = carat, y = price, color = color)) +
labs(color = "color legend")

ggplot(data = data) +
geom_point(aes(x = carat, y = price,
shape = cut)) +
labs( shape = " shape legend")

修改标签名
ggplot(data =mtcars) + geom_point(aes(x = wt,
y = mpg,
color = factor(cyl))) +
scale_color_discrete(labels = c("don't like",
"like in small doses",
"like in large doses"))
