R语言中 ggplot函数中 annotate选项

 

001、基础绘图

library(ggplot2)
p <- ggplot(faithful, aes(x = eruptions, y = waiting)) + 
  geom_point()                  ## 基础绘图
p

002、增加文本

p + annotate("text", x = 3, y = 48, label = "Group 1") + 
annotate("text", x = 4.5, y = 66, label = "Group 2")          ## 增加文本

 

003、   ## 设置颜色、字体、大小等

p + annotate("text", x = 3, y = 48, label = "Group 1", 
    family = "serif", fontface = "italic", colour = "darkred",
    size = 5) + annotate("text", x = 4.5, y = 66, 
    label = "Group 2", family = "serif", fontface = "italic", 
    colour = "darkred", size = 5)            ## 设置颜色、字体、大小等

 

004、 等价geom_text

p + annotate("text",x=3,y=48,label="Group 1", alpha=.1) +
  geom_text(x=4.5, y=66, label="Group 2", alpha=.1)          ## 等价geom_text

 

005、指定位置02

p + annotate("text", x = -Inf, y = Inf, label = "Upper left", 
             hjust = -0.2,vjust = 2) + 
annotate("text", x = mean(range(faithful$eruptions)), y = -Inf, 
                      vjust = -0.4, label = "Bottom middle")       ## 指定位置02

 

 

来源:https://blog.csdn.net/g_r_c/article/details/19673625

 

posted @   小鲨鱼2018  阅读(256)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-07-10 使用plink、gemma软件进行gwas分析增加协变量
2022-07-10 主板EATX、ATX、MATX、ITX
2022-07-10 gemma、plink使用一般线性模型进行GWAS分析
2021-07-10 判断系列向量组的线性相关性a1=(1,1,2,0),a2=(1,2,3,-1), a3=(-1,1,0,-2)
2021-07-10 linux系统中tee命令
2021-07-10 若向量组A可由向量组B线性表示,则R(A) <= R(B)
点击右上角即可分享
微信分享提示