GGPLOT: 美化线图文本注释展示

1、线图线条上插入注释


更多样式和代码参考 : AllanCameron/geomtextpath: Create curved text paths in ggplot2 (github.com)
geom_textline 简单用法:

data %>% 
    ggplot(aes(x, y)) +
    geom_textline(label = "Mercury vapor pressure", color = "deepskyblue4", linewidth=2)

2、副轴添加注释标签 -- sec.axis


示例代码

dt <- readr::read_tsv("https://bit.ly/3dqO4V9") ### readr可以 自动解析 date 变量
dt_label <- dt %>%  group_by(company) %>% summarize(last = dplyr::last(price))
dt %>%
    ggplot(aes(x=date, y=price, color=company)) +
    geom_step(linewidth = 0.8,direction = "vh") +
    scale_x_date(expand = c(0,0)) +
    scale_color_brewer(palette = "Set1",guide  = NULL) +
    scale_y_continuous(
        limits = c(0, 3600),expand = c(0,0),
        sec.axis = dup_axis(breaks = dt_label$last,labels = dt_label$company,name = NULL)
    ) +
    theme_bw() + theme(,axis.text.y.right = element_text(size = 15,color = "#0d569f")) +
    labs(title = "sec.axis label", x = "" ,y  ="")

代码参考:
How to Add Labels Directly in ggplot2. Hint: Use Secondary Axis Trick - Data Viz with Python and R (datavizpyr.com)
Line graph in ggplot2 [geom_line and geom_step] | R CHARTS (r-charts.com)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容

  • 8 注释 在构建数据可视化时,通常需要对显示的数据进行注释。从概念上讲,注释为图提供元数据:也就是说,它提供关于所...
    denghb001阅读 9,048评论 0 3
  • 作者:严涛浙江大学作物遗传育种在读研究生(生物信息学方向)伪码农,R语言爱好者,爱开源 ggplot2学习笔记之图...
    Dylan的迪阅读 7,622评论 0 6
  • ggplot2画图展示时,可用sec.axis直接添加标签。 核心函数: 示例数据是科技公司随着时间变化的数据(时...
    高大石头阅读 9,786评论 0 3
  • “The simple graph has brought more information to the dat...
    凡有言说阅读 5,234评论 0 4
  • !备忘,方便自己查询,随着使用更新,无参考价值。 Function reference[https://ggplo...
    shwzhao阅读 4,666评论 0 7