forked from duty-machine/duty-machine
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: "circos图转换新风格" | ||
date: 2024-05-10T13:15:42Z | ||
draft: ["false"] | ||
tags: [ | ||
"fetched", | ||
"R语言数据分析指南" | ||
] | ||
categories: ["Acdemic"] | ||
--- | ||
circos图转换新风格 by R语言数据分析指南 | ||
------ | ||
<div><section data-tool="mdnice编辑器" data-website="https://www.mdnice.com"><h3 data-tool="mdnice编辑器"><span></span><span><span></span>欢迎关注R语言数据分析指南</span><span></span></h3><blockquote data-tool="mdnice编辑器"><span>❝</span><p>本节来介绍如何在绘制circos图时通过构建图例的形式来展示文本,避免图表文本过多产生视觉混乱,图表无实际意义,整个过程仅参考。希望对各位观众老爷能有所帮助。<strong>「代码会整合上传到学习交流群」</strong>,购买过小编R数据可视化文档的朋友可在所加的交流群内获取下载,有需要的朋友可关注文中介绍加入交流群。</p><span>❞</span></blockquote><h3 data-tool="mdnice编辑器"><span></span><span><span></span>图形展示</span><span></span></h3><figure data-tool="mdnice编辑器"><img data-imgfileid="100028350" data-ratio="0.9787037037037037" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vX2HrAeTfgKmiafLXsc4NWNPaK8FrwPZiceQ8sy4kuL3gFdviaRTogAynA/640?wx_fmt=png&from=appmsg" data-type="png" data-w="1080" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vX2HrAeTfgKmiafLXsc4NWNPaK8FrwPZiceQ8sy4kuL3gFdviaRTogAynA/640?wx_fmt=png&from=appmsg"></figure><h3 data-tool="mdnice编辑器"><span></span><span><span></span>图形解读</span><span></span></h3><blockquote data-tool="mdnice编辑器"><span>❝</span><p>通过批量构建图例来展示弦图右侧的文本,避免文本过多引起图形凌乱。由于有27个文本在颜色配置上使用了重复色,实际分析中应分配27种颜色。</p><span>❞</span></blockquote><h3 data-tool="mdnice编辑器"><span></span><span><span></span>加载R包</span><span></span></h3><pre data-tool="mdnice编辑器"><span></span><code><span>library</span>(tidyverse)<br><span>library</span>(circlize)<br><span>library</span>(cowplot)<br><span>library</span>(RColorBrewer)<br><span>library</span>(magrittr)<br><span>library</span>(ComplexHeatmap)<br><span>library</span>(grid)<br></code></pre><h3 data-tool="mdnice编辑器"><span></span><span><span></span>R包版本号</span><span></span></h3><p data-tool="mdnice编辑器">sessionInfo()<img data-imgfileid="100028347" data-ratio="0.18703703703703703" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vG1FtxwicQh0H6IKqgYW9qxBVuP4BictTAoj6QLUUfuWK7AHObSTI3IZQ/640?wx_fmt=png&from=appmsg" data-type="png" data-w="1080" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vG1FtxwicQh0H6IKqgYW9qxBVuP4BictTAoj6QLUUfuWK7AHObSTI3IZQ/640?wx_fmt=png&from=appmsg"></p><h3 data-tool="mdnice编辑器"><span></span><span><span></span>导入数据</span><span></span></h3><pre data-tool="mdnice编辑器"><span></span><code>df <- read_csv(<span>"loadouts.txt"</span>) %>% select(<span>2</span>,<span>6</span>)<br><span># 定义布局</span><br>circos.par(canvas.xlim=c(-<span>0.6</span>,<span>0.2</span>),canvas.ylim=c(-<span>1</span>,<span>1</span>),start.degree =-<span>90</span>)<br><br><span># 定义左侧颜色</span><br>grid.col1 =c(`1`=<span>"#B2182B"</span>,`2`=<span>"#D6604D"</span>,`3`=<span>"#F4A582"</span>,`4`=<span>"#FDDBC7"</span>,<br> `5`=<span>"#F7F7F7"</span>,`6`=<span>"#D1E5F0"</span>,`7`=<span>"#92C5DE"</span>,`8`=<span>"#4393C3"</span>,`9`=<span>"#2166AC"</span>)<br><br><span># 定义右侧颜色</span><br>grid.col2 <- df %>% select(<span>2</span>) %>% distinct() %>% <br> bind_cols(brewer.pal(<span>12</span>,<span>"Paired"</span>) %>% as.data.frame() %>% <br> bind_rows(brewer.pal(<span>12</span>,<span>"Paired"</span>) %>% as.data.frame()) %>% <br> bind_rows(brewer.pal(<span>3</span>,<span>"Paired"</span>) %>% as.data.frame())) %>% <br> set_colnames(c(<span>"name"</span>,<span>"col"</span>)) %>% <br> deframe()<br><br><span># 颜色合并</span><br>grid.col <- c(grid.col1,grid.col2)<br>set.seed(<span>1234</span>)<br><br><span># 绘制弦图</span><br>chordDiagram(df,grid.col=grid.col, <br> link.decreasing = <span>TRUE</span>, transparency = <span>0.1</span>, <br> big.gap = <span>10</span>,<br> link.sort = <span>FALSE</span>,annotationTrack = <span>"grid"</span>,<br> preAllocateTracks = list(track.height = <span>.2</span>))<br></code></pre><h3 data-tool="mdnice编辑器"><span></span><span><span></span>关注下方公众号下回更新不迷路</span><span></span></h3><section><mp-common-profile data-pluginname="mpprofile" data-id="Mzg3MzQzNTYzMw==" data-headimg="http://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAZF0rpeZII9Ltl26VbVagriczTria1fib3XgjwwHEHFjPzkmGpqWDVVHBSzhENictUM2iavAKiaM5lc9USw/0?wx_fmt=png" data-nickname="R语言数据分析指南" data-alias="YanJANtwo" data-signature="R语言重症爱好者,喜欢绘制各种精美的图表,喜欢的小伙伴可以关注我,跟我一起学习" data-from="0" data-is_biz_ban="0"></mp-common-profile></section><blockquote data-tool="mdnice编辑器"><span>❝</span><p>本节介绍到此结束,有需要学习R数据可视化的读者,欢迎购买小编的R数据可视化案例文档,<strong>「购买将自动获得2024年度更新的绘图文档代码,无需在付费」</strong>。目前此文档(2023+2024)<strong>「已经更新上传了150+案例文档」</strong>,每个案例都附有相应的数据和代码,并配有对应的注释文档,方便大家学习和参考。可到小编的<strong>「淘宝店铺-R语言数据分析指南」</strong>下单购买。</p><span>❞</span></blockquote><p data-tool="mdnice编辑器"><strong>「2024更新的绘图内容同时包含数据+代码+markdown注释文档+文档清单」</strong></p><p data-tool="mdnice编辑器">注:2022版与2023版文档为单独售卖,买任意一年的都可获取2024的文档,<strong>「小编只分享案例文档不额外回答问题。」</strong></p><h3 data-tool="mdnice编辑器"><span></span><span><span></span>淘宝店铺</span><span></span></h3><p><img data-galleryid="" data-imgfileid="100019415" data-ratio="1.0210420841683367" data-s="300,640" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/EibnicgwScTAbvhPDLGT8NaialEsht92PTYNJWpmVLfoYGic1uha5FyBrDCibibZCLjiazgvpT1XcdwibfVywD2el0VAgg/640?wx_fmt=jpeg" data-type="jpeg" data-w="998" src="https://mmbiz.qpic.cn/mmbiz_jpg/EibnicgwScTAbvhPDLGT8NaialEsht92PTYNJWpmVLfoYGic1uha5FyBrDCibibZCLjiazgvpT1XcdwibfVywD2el0VAgg/640?wx_fmt=jpeg"></p><h3 data-tool="mdnice编辑器"><span></span><span><span></span>2024年案例图展示</span><span></span></h3><p data-tool="mdnice编辑器"><img data-imgfileid="100028348" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vU8cTgDUnMJsYjrY8NIONh1gNac75e13IRZCX6td7iajMiaT6qAopicb3Q/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vU8cTgDUnMJsYjrY8NIONh1gNac75e13IRZCX6td7iajMiaT6qAopicb3Q/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028346" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vS5jf59Vkt5A2qB5jhnNxJ4XE5MYu6YZnDCwECEnCx1mFI7sIbOw3kQ/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vS5jf59Vkt5A2qB5jhnNxJ4XE5MYu6YZnDCwECEnCx1mFI7sIbOw3kQ/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028349" data-ratio="0.48148148148148145" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vzfe4dO6UIsCbkRriavBMvpTFeQlF6SibzgLSKaSLwkkfGQH6AviaOjEIw/640?wx_fmt=png&from=appmsg" data-type="png" data-w="1080" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vzfe4dO6UIsCbkRriavBMvpTFeQlF6SibzgLSKaSLwkkfGQH6AviaOjEIw/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028352" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vTSMqoA7Mzdvd512ke1KnPiaQZTDEacf6OXOD9XJn1N2C6RqCT7lAO9A/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vTSMqoA7Mzdvd512ke1KnPiaQZTDEacf6OXOD9XJn1N2C6RqCT7lAO9A/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028353" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vZAFAzZ0LX944Mtd8DmEiaSqCIOwSicXvfia4U2naT7TyHhh9CCL5ZOhBQ/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vZAFAzZ0LX944Mtd8DmEiaSqCIOwSicXvfia4U2naT7TyHhh9CCL5ZOhBQ/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028351" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3veCGH0zBrqAAbh2dQAicPxbSwG6b7tfFZZ52w6Qo7cPedml6WW1sdMQg/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3veCGH0zBrqAAbh2dQAicPxbSwG6b7tfFZZ52w6Qo7cPedml6WW1sdMQg/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028354" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vSQPoh08xaseeIu35BMD3donwibfnGMIwpUFTibpU9NH6ONMwhEo94SIg/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vSQPoh08xaseeIu35BMD3donwibfnGMIwpUFTibpU9NH6ONMwhEo94SIg/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028355" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3v9cWWyFhrvahxZyRPCDeBxFIXNvmO5NogXNichxznkmewGgmJmHicVQ0A/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3v9cWWyFhrvahxZyRPCDeBxFIXNvmO5NogXNichxznkmewGgmJmHicVQ0A/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028359" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vmLTgiayvzVhPvsbicw9d1iaypWvaHWdNMhbqhIXwdH6Gq3eyHuwCiawjgA/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vmLTgiayvzVhPvsbicw9d1iaypWvaHWdNMhbqhIXwdH6Gq3eyHuwCiawjgA/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028360" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vc6dbclH8GSJSc8EKibBYx6t0V3oRAZ8GZxU69psdicmmRjibiccrxyJJwA/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vc6dbclH8GSJSc8EKibBYx6t0V3oRAZ8GZxU69psdicmmRjibiccrxyJJwA/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028356" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vQ8kr8XWSDnhqsFpnXV48OVgA3E7SnowjT6aa8SC9mUEuYWRMGG4PVA/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vQ8kr8XWSDnhqsFpnXV48OVgA3E7SnowjT6aa8SC9mUEuYWRMGG4PVA/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028358" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3v895MibIgibiaseOKY5ZslSWvugpl5lJXlB70FGXhUyIkkbmSibZzy8icz8Q/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3v895MibIgibiaseOKY5ZslSWvugpl5lJXlB70FGXhUyIkkbmSibZzy8icz8Q/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028357" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vo4m71rJ36pwHcpe1GVO42U9WpC6Ua1onp03tp8JhhcovlBlXoyIUDQ/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3vo4m71rJ36pwHcpe1GVO42U9WpC6Ua1onp03tp8JhhcovlBlXoyIUDQ/640?wx_fmt=png&from=appmsg"><img data-imgfileid="100028365" data-ratio="0.4255555555555556" data-src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3v1mrScqY877jp9Kk8LbM4sGKpiczaAckqEiaLM3kzGC5bAtZ9LicOYcicQQ/640?wx_fmt=png&from=appmsg" data-type="png" data-w="900" src="https://mmbiz.qpic.cn/mmbiz_png/EibnicgwScTAblXl6Sib2l6UNQHwicLX9U3v1mrScqY877jp9Kk8LbM4sGKpiczaAckqEiaLM3kzGC5bAtZ9LicOYcicQQ/640?wx_fmt=png&from=appmsg"></p></section><p><mp-style-type data-value="3"></mp-style-type></p></div> | ||
<hr> | ||
<a href="https://mp.weixin.qq.com/s/cZXqtea312G8gehGuiDccA",target="_blank" rel="noopener noreferrer">原文链接</a> |