R语言绘图(5)-ggplot2学习笔记添加文本注释text,label

geom_text()

geom_text(
mapping = NULL,
data = NULL,
stat = “identity”,
position = “identity”,
…,
parse = FALSE,
nudge_x = 0,
nudge_y = 0,
check_overlap = FALSE,
hjust=‘center’,
vjust=‘center’
angel=0
size=4
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE)

mapping = NULL,
data = NULL,

如果在前面有对应的ggplot(data,aes(x,y)),那么geom_text(mapping,data)则继承该参数,否则需用户自己提供指定。

stat = “identity”,
该图层数据的统计变换,为字符串

position
位置调整,字符串

nudge_x = 0,
nudge_y = 0,

水平或者垂直调整text与数据点的距离,避免遮挡
ggplot(df, aes(x, y)) +geom_point()+geom_text(aes(label = text),nudge_x=0,nudge_y=0)
在这里插入图片描述
ggplot(df, aes(x, y)) +geom_point()+geom_text(aes(label = text),nudge_x=0.1,nudge_y=0.1)
在这里插入图片描述
check_overlap = FALSE 是否要覆盖同一图层中之前的text注释,多指数据点较多,文本之间重叠严重时

position text文本位置信息在这里插入图片描述
ggplot(df, aes(x, y)) +geom_point()+geom_text(aes(label = text),position=position_dodge(width=0.5))

vjust,hjust
text一般默认文本对齐方式为‘center’居中对齐,可以通过hjust和vjust方法调整文字对齐方式
ggplot(df, aes(x, y)) +geom_point()+geom_text(aes(label = text),position=position_dodge(width=0.5),vjust='inward',hjust='inward')
'inward’表示居中对齐
在这里插入图片描述
ggplot(df, aes(x, y)) +geom_point()+geom_text(aes(label = text,color=y),position=position_dodge(width=0.5),vjust='inward',hjust='inward',angle=45,size=4)
在这里插入图片描述
geom_label()
ggplot(df, aes(x, y)) +geom_point()+geom_label(aes(label = text,color=y),position=position_dodge(width=0.5),vjust='inward',hjust='inward',angle=45,size=4)
在这里插入图片描述

  • 4
    点赞
  • 67
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值