首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏北野茶缸子的专栏

    91-R可视化23-底层绘图系统grid学习之grob对象

    2-grob 对象 grob 用来控制grid 绘图的主要元素,包括以下方法:circleGrob, linesGrob, polygonGrob, rasterGrob, rectGrob, textGrob 此外,除了grid 可以创建grob 对象外,还有其他包包括gridExtra 也可以创建grob 对象如tableGrob。 2.1-第一个grob 对象 我们可以直接通过上述的grob 方法创建对应的grid 对象,比如: my_circle <- circleGrob(x = 0.5, y = 0.5, r = 0.5, 2.2-编辑grob 对象 我们可以使用grid.edit函数,实时对grid 画板上的grob 对象进行修改: my_circle <- circleGrob(name = "my_circle",x 2.4-将grob 对象组合 上述的步骤里,我们通过grid.force,将ggplot 的grob 元素进行了拆分,那么我们可否将我们自行创建的grob 对象组合呢?

    1.2K20编辑于 2022-02-08
  • 来自专栏小明的数据分析笔记本

    跟着Nature Plants学作图:R语言ggplot2画分组折线图并对坐标轴添加一些额外注释

    geom_text(data=dftext,aes(x=x,y=y,label=label))+ coord_cartesian(clip = "off")+ annotation_custom(grob xmin=0,xmax=100, ymin=-0.08, ymax=-0.08)+ annotation_custom(grob =125,xmax=225, ymin=-0.08, ymax=-0.08)+ annotation_custom(grob xmin=0,xmax=1, ymin=-0.08, ymax=-0.08)+ annotation_custom(grob =124,xmax=125, ymin=-0.08, ymax=-0.08)+ annotation_custom(grob

    1.3K20编辑于 2023-01-06
  • 来自专栏R语言数据分析指南

    分面绘图注释增强版之annotation_custom2

    library(ggh4x) library(ggsignif) library(ggsci) library(grid) 定义函数 annotation_custom2 <- function (grob PositionIdentity, geom = ggplot2:::GeomCustomAnn, inherit.aes = TRUE, params = list(grob ymin = ymin, ymax = ymax)) } 定义文本 grob <- grobTree(textGrob("Scatter plot", x=0.1, y=0.95, hjust=0, =="Petal.Length"), ymin =2, ymax=2, xmin=0.8, xmax=Inf)+ annotation_custom2(grob "Petal.Length"), ymin =2.1, ymax=2.1, xmin=1.8, xmax=2)+ annotation_custom2(grob

    72520编辑于 2022-09-21
  • 来自专栏R语言数据分析指南

    ggplot2分面图形自定义添加回归曲线R值

    PositionIdentity, geom = ggplot2:::GeomCustomAnn, inherit.aes = TRUE, params = list(grob ymin = ymin, ymax = ymax)) } 构建文本信息 grob1 <- grobTree(textGrob(expression(paste(italic(R^2),"=0.25, 0.001")), x=0.1,y=0.95, hjust=0,gp=gpar(col="#DC0000FF", fontsize=10))) grob2 legend.key = element_blank(), legend.title = element_blank())+ annotation_custom2(grob1 (grob3,data=df %>% filter(year==1982))

    1.2K10编辑于 2022-12-20
  • 来自专栏生信菜鸟团

    R包:gtable包用于处理ggplot2图像

    ggplot2是基于grid的绘图工具,它绘制的图像其实是由多个grob(grid graph object)组成的,比如一张点图,它的标题是titleGrob,点图的基本单元包括pointsGrob。 gtable可以个性化修改定制这些grob对象,从而可以对gplot2绘图对象进行更加高阶的定制,比如拼图、图中嵌图等。 填充图形是使用的gtable_add_grob实现的。 (1, 1), "null"), heights = unit(1, "null")) # 将两张图片分别放入gtable中 # gtable_add_grob (align_grobs[[1]]) + draw_grob(align_grobs[[2]]) ?

    2.9K30发布于 2020-10-12
  • 来自专栏生信技能树

    一文了解热图如何添加文本框注释

    grid是R语言中的一个基础图形包,用于创建和操作图形对象(grob,即图形对象)。它提供了低层次的图形绘制功能,允许用户以高度灵活的方式构建复杂的图形。 现在来看看具体的函数用法:textbox_grob。 textbox_grob函数里面的参数解释: words应该是一个字符向量,包含了要显示的文本。 word_wrap = TRUE:根据文本框的宽度调整文本 add_new_line = TRUE:每一个sentences一行 gb = textbox_grob(words),grobWidth(gb (words, line_space = unit(15, "mm")) grid.draw(gb) 设置单词之间的距离: grid.newpage() gb = textbox_grob(words (5, 8) sentences fontsize = runif(5, 5, 20) fontsize grid.newpage() gb = textbox_grob(sentences, gp

    36200编辑于 2025-07-02
  • 来自专栏小明的数据分析笔记本

    跟着GlobalChangeBiology学作图:R语言ggplot2点线图(2)给分面添加注释

    '),有了基本思路就可以尝试一下这个图 image.png 今天的推文主要介绍如何给每个分面单独添加注释,这里需要用到一个自定义函数 annotation_custom2 <- function (grob PositionIdentity, geom = ggplot2:::GeomCustomAnn, inherit.aes = TRUE, params = list(grob p1+ annotation_custom2( data = dat %>% filter(group01=="(a) Litter addition vs. removal"), grob annotation_custom2( data = dat %>% filter(group01=="(a) Litter addition vs. removal"), grob = element_rect(fill="transparent")) -> p3 p3 image.png 给坐标轴的文本添加背景色 p3+ annotation_custom2( grob

    89811编辑于 2023-01-06
  • 来自专栏优雅R

    「R」ggplotify——连接各类R图形

    (~barplot(1:10)) p2 <- as.grob(expression(plot(rnorm(10)))) p3 <- as.grob(function() plot(sin)) library ("vcd") data(Titanic) p4 <- as.grob(~mosaic(Titanic)) library("lattice") data(mtcars) p5 <- as.grob(densityplot (~mpg|cyl, data=mtcars)) as.grob 函数接收绘制图形的 expression、公式或者函数等。 因为这里将图形转换为了grob对象,所以它兼容grid图形系统与相关工具包。 我们现在可以使用grid.draw绘制p1和p2,以及使用pushViewport进行图形嵌入。 ggplot2 所有可以转换为grob对象的图形都可以使用as.ggplot函数转换为ggplot对象。

    1.7K30发布于 2020-07-06
  • 来自专栏生信宝典

    ggplot2学习笔记之图形排列

    <- ggarrange(sp, bp+font("x.text", size = 10), ncol = 1, nrow = 2) annotate_figure(figure, top=text_grob ("Visualizing mpg", color = "red", face = "bold", size=14), bottom = text_grob("Data source:\n mtcars ggplot图形中嵌入图形元素 ggplot2::annotation_custom()可以添加各种图形元素到ggplot图中 annotation_custom(grob, xmin, xmax, inside the scatter plots p+annotation_custom(grob = xbp_grob, xmin = xmin, xmax = xmax, ymin = ymin-yoffset , ymax = ymin+yoffset)+ # Insert ybp_grob inside the scatter plot annotation_custom(grob = ybp_grob,

    2.8K20发布于 2018-12-18
  • 来自专栏北野茶缸子的专栏

    111-R可视化35-结合grid与ggplot输出

    1-通通拆成grob处理 既然ggplot 本质也是grid,那我把ggplot 拆成最底层,再慢慢处理,不也是可以的吗? , and the grob will not be modified by any ggplot settings or mappings). ” 参数如下: grobgrob to display 虽然grid_panel 也限定在了坐标轴的范围内,但其厉害之处在于可以接受函数作为grob 输入。 `:Either a grid grob or a function. 如果是更加自由地使用,还是选择拆成grob 再各自处理的方案。 但如果你的grid 使用并不熟练,且需要的功能并不复杂,那么直接打印,也不失为一个对策。

    1.1K20编辑于 2022-04-05
  • 来自专栏北野茶缸子的专栏

    101-R可视化29-底层绘图系统grid学习之使用grid作图

    》 4.7 Building New Graphical Elements | Mastering Software Development in R (bookdown.org)[1] 前言 学习了grob baseViewports()$plot) grid.show.viewport(dataViewport(irisPetal.Length, irisPetal.Width)) 直接通过数据来适配画布: grob 除了[[91-R可视化23-底层绘图系统grid学习之grob对象]] 中介绍的,先通过xxGrob 方法获得grob 对象,我们还可以直接调用grid.xx 进行绘图,比如: vp_background 亦或是说,我们如何通过组合grob 在不同图纸下一步步作出ggplot 的整合体呢? 也留个坑吧,不知道能不能做到。

    75220编辑于 2022-04-05
  • R可视化:ggpubr的基本图形

    (pmain, xdens, grid::unit(.2, "null"), position = "top")p2 <- insert_yaxis_grob(p1, ydens, grid::unit (.2, "null"), position = "right")ggdraw(p2)第四种方法,通过grob设置# Scatter plot colored by groups ("Species") <- ggplotGrob(xbp)ybp_grob <- ggplotGrob(ybp)# Place box plots inside the scatter plot#::::::::::::: inside the scatter plotsp + annotation_custom(grob = xbp_grob, xmin = xmin, xmax = xmax, (grob = ybp_grob, xmin = xmin-xoffset, xmax = xmin+xoffset,

    65410编辑于 2024-06-11
  • 来自专栏数据 学术 商业 新闻

    可视化绘制技巧|对多图合理排版布局

    函数的格式如下: annotation_custom(grob, xmin, xmax, ymin, ymax) grob:要显示的外部图形元素。 = ggplotGrob(p2) p3_grob = ggplotGrob(p3) # 合并图形 p1 + annotation_custom(grob = p2_grob, xmin = 0, 然后将图形使用ggplotGrob函数转换成为一个图形元素(grob对象)。最后使用annotation_custom函数添加创建好的图形元素。 代码 ’p1 + annotation_custom(grob = p2_grob, xmin = 0, xmax = 5,ymin = -2, ymax = 0)’ 表示将p2_grob这个图形元素添加到 # 在散点图中插入p3_grob p1 + annotation_custom(grob = p3_grob, xmin = -6, xmax = -2,ymin = -3, ymax =2) ?

    3.4K20发布于 2021-02-22
  • 来自专栏R语言数据分析指南

    [GBD数据库挖掘2] ggplot2优雅的展示发病率

    = elem_list_rect(fill = c("#EEECE1","#FFF2E7","#E8F2FC"))) 定义注释函数 annotation_custom2 <- function (grob PositionIdentity, geom = ggplot2:::GeomCustomAnn, inherit.aes = TRUE, params = list(grob = grob, xmin = xmin, xmax = xmax, legend.key.height=unit(0.5,'cm'), legend.background=element_blank())+ annotation_custom2(grob

    86020编辑于 2022-09-23
  • 来自专栏优雅R

    「R」grid 图形对象 grobs

    grobs 的创建通常使用以 Grob 作为后缀的函数们,包括circleGrob, linesGrob, polygonGrob, rasterGrob, rectGrob, segmentsGrob grid.edit("GRID.text.1419", gp = gpar(fontface = "bold")) ggplot2 包中的 ggplotGrob() 函数可以将 ggplot 对象转化为 grob gTree grob 可以包含多个子 grob(即组装多个子对象),可以用于像箱线图这种复杂的图形中。

    1.5K10发布于 2021-06-16
  • R语言绘图 | 渐变火山图

    label = "p = 0.05",            size = 5) +   coord_cartesian(clip = "off") +   annotation_custom(     grob range(-log10(df$padj))[2]/10*9.5,     ymax = range(-log10(df$padj))[2]/10*9.5 ) +   annotation_custom(grob padj))[2]/10*9.5,                     ymax = range(-log10(df$padj))[2]/10*9.5 ) +   annotation_custom(grob padj))[2]/10*9.5,                     ymax = range(-log10(df$padj))[2]/10*9.5 ) +   annotation_custom( grob

    28800编辑于 2025-05-29
  • 来自专栏数据 学术 商业 新闻

    R语言统计与绘图:给组合图形添加ABCD小标签

    <- ggarrange(p1, p2, p3, p4, ncol = 2, nrow = 2) annotate_figure(figure, top = text_grob ("给组合图形添加标签", color = "red", face = "bold", size = 14), bottom = text_grob("公众号: R语言统计与绘图 hjust = 1, x = 1, face = "italic", size = 10), left = text_grob c("none", "h", "v", "hv"), widths = 1, heights = 1, legend = NULL, common.legend = FALSE, legend.grob

    8.9K20发布于 2021-02-22
  • 来自专栏VRPinea

    高通:VR头显将缩小到眼镜大小,5G将把VR推向主流

    高通CTO Matt Grob说道:“即使有更先进的独立头显,在5G推出之前,VR和AR将不会成为大众市场的主流产品。” “5G将让我们在任何地方直播高品质的360度VR内容。 这就能够促使Magic Leap等公司将好莱坞大片式的图片实时提供到大量的用户手中,” Grob说道。 另外,高通公司还发布了全球第一款5G调制解调器:骁龙 X50。 Grob宣称该技术将允许企业打造“超越4K”的体验,他解释说:“当我谈及‘超越4K’的时候,你或许会思考为什么要超越4K。 这将允许所有人都能拥有VR和AR体验,” Grob接着说道。 高通并不是唯一一家希望使用5G来促进其AR / VR发展的公司。

    1.1K60发布于 2018-05-14
  • 来自专栏北野茶缸子的专栏

    96-R可视化25-底层绘图系统grid学习之viewports

    ] (11条消息) R语言grid包使用笔记——viewport_数据之美-CSDN博客_r语言grid包[3] 书本《R 绘图系统》 前言 接着前面[[91-R可视化23-底层绘图系统grid学习之grob 1-我的第一个Viewports 如果说grob 对象是画布上一个个具体的图形,那么Viewports就是画布上的具体的画图区域。 Viewports 上的: grid.draw(rectGrob(gp = gpar(col = "pink", lwd = 4))) 类似grob 这里的操作非常的像base 包里的逻辑,如果我们不清除这个画布上的内容,还可以把上述两个大图结合起来: 4-结合grob 对象 library(ggmap) balt_counties <- map_data 此外,我们也可以利用grid.ls 获得画布的全部grob 对象名称: > grid.ls() GRID.roundrect.361 GRID.gTree.359 GRID.circle.357

    83830编辑于 2022-04-05
  • 来自专栏作图丫

    独特的箱型图版式,你学会了吗?

    功能展示 ##帮助将econodist图例添加到ggplot2绘图 add_econodist_legend() ##创建一个可以与econodist图表一起使用的图例grob econodist_legend_grob + theme_ipsum_rc() -> gmgg grid.newpage() gmgg %>% add_econodist_legend( econodist_legend_grob grid.newpage() left_align(gg, c("subtitle", "title", "caption")) %>% add_econodist_legend(econodist_legend_grob

    1.2K10编辑于 2022-03-29
领券