tidyplots学习超详细注释版-基于Cursor-(13)

<p>
</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-05f810ef67befa7e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>教程地址:https://jbengler.github.io/tidyplots/articles/Color-schemes.html</p><p>在本文中,我们将演示在tidyplots中使用配色方案。我们将探索tidyplots附带并可用于绘图的默认配色方案。其中包括离散、连续和边缘变量的方案。最后,我们将讨论从十六进制值创建自定义配色方案</p><h1>默认配色方案</h1><p>tidyplots带有许多默认配色方案。其中许多是从viridisLite和RColorBrewer软件包改编而来的。您可以通过加载tidyplots库并开始输入colors_来访问它们。自动完成将引导您选择离散、连续和发散的方案。</p><p>让我们看看tidyplotscolors_discrete_friendly的方案,它被设计用于色觉缺陷的人。当在控制台或脚本中运行colors_discrete_friendly时,该方案的预览将呈现到RStudio桌面界面右下角的查看器窗格中。</p><p>本质上,tidyplots配色方案只是一个十六进制颜色的字符向量,具有将预览发送到RStudio查看器窗格的特殊打印方法。</p><pre>library(tidyplots)colors_discrete_friendly</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-a0413b1da91b4a56.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>提示:您可以直接从预览中复制单个十六进制颜色以在脚本中使用它们。</p><h1>离散的</h1><p>离散配色方案适用于分类变量。整齐图中的默认方案由5-7种颜色组成。但是,如果图中存在更多类别,整齐图将自动填补颜色之间的空白,以准确地提供为图重新查询的数字。</p><p>类似地,当提供的颜色多于需要时,tidyplots将通过尝试从提供的颜色向量中均匀采样来选择所需数量的颜色。</p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute()</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-15af2e0903289938.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>这里有一些可供选择的配色方案。</p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(colors_discrete_seaside)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-40bc39fe257132d1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(colors_discrete_friendly_long)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-b1dcf8bcee3ccea9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(colors_discrete_apple)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-6dbacc0ba1cc99f8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(colors_discrete_ibm)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-da10d47932d1b1af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(colors_discrete_candy)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-055f7505946a1532.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(colors_discrete_alger)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-61205044ff514cfd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(colors_discrete_rainbow)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-6b65d420146f81f4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1>连续的</h1><p>连续配色方案适用于连续变量。tidyplots中的默认方案通常由265种颜色组成。</p><pre>colors_continuous_viridis</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-ef9f4277372b069c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>这是一个连续配色的用例。</p><pre>climate %>%   tidyplot(x = month, y = year, color = max_temperature) %>%   add_heatmap()</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-a23a0c0a4a4129ad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/>这里有一些替代配色方案。</p><pre>climate %>%   tidyplot(x = month, y = year, color = max_temperature) %>%   add_heatmap() %>%   adjust_colors(new_colors = colors_continuous_inferno)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-db4b9b22c94dfe32.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>climate %>%   tidyplot(x = month, y = year, color = max_temperature) %>%   add_heatmap() %>%   adjust_colors(new_colors = colors_continuous_mako)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-85049fe79cc01dac.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>climate %>%   tidyplot(x = month, y = year, color = max_temperature) %>%   add_heatmap() %>%   adjust_colors(new_colors = colors_continuous_turbo)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-a8a0144ea2e18d83.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>climate %>%   tidyplot(x = month, y = year, color = max_temperature) %>%   add_heatmap() %>%   adjust_colors(new_colors = colors_continuous_rocket)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-61061d0672120268.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1>中心配送方案</h1><p>中心配色方案适用于中间有中心点的连续变量。一个经典的例子是用于基因表达热图的蓝-白-红渐变。</p><pre>colors_diverging_blue2red</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-99e0af4c18389074.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>这是一个中心配色的用例。</p><pre>gene_expression %>%   tidyplot(x = sample, y = external_gene_name, color = expression) %>%   add_heatmap(scale = "row") %>%  sort_y_axis_labels(direction) %>%   adjust_size(height = 100)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-c9e839e60acaa704.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>这里有一些替代的配色方案。</p><pre>gene_expression %>%   tidyplot(x = sample, y = external_gene_name, color = expression) %>%   add_heatmap(scale = "row") %>%  sort_y_axis_labels(direction) %>%   adjust_size(height = 100) %>%   adjust_colors(new_colors = colors_diverging_blue2brown)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-b4ea86ab2acf279c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>gene_expression %>%   tidyplot(x = sample, y = external_gene_name, color = expression) %>%   add_heatmap(scale = "row") %>%  sort_y_axis_labels(direction) %>%   adjust_size(height = 100) %>%   adjust_colors(new_colors = colors_diverging_spectral)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-9f2aed57294673ef.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>gene_expression %>%   tidyplot(x = sample, y = external_gene_name, color = expression) %>%   add_heatmap(scale = "row") %>%  sort_y_axis_labels(direction) %>%   adjust_size(height = 100) %>%   adjust_colors(new_colors = colors_diverging_icefire)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-4454bf1a9c67fddc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1>自定义配色方案</h1><p>当然,您也可以使用new_color_scheme()函数构建自定义配色方案。</p><pre>my_colors <-   new_color_scheme(c("#ECA669","#E06681","#8087E2","#E2D269"),                   name = "my_custom_color_scheme")my_colors</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-ddb768d88f1c5c71.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-28e8a1cce3a51562.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>那么您可以使用您的方案作为adjust_colors()函数的输入。</p><pre>energy %>%   tidyplot(year, energy, color = energy_source) %>%   add_barstack_absolute() %>%   adjust_colors(new_colors = my_colors)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-36dc43291b6f1001.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>除了创建新方案之外,你还可以以与处理常规字符串完全相同的方式对现有方案进行子集划分和连接。</p><pre>colors_discrete_metro[2]</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-15ed0a14dbc95f06.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>colors_discrete_metro[2:4]</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-b1f05e046e7933bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><pre>c(colors_discrete_metro, colors_discrete_seaside)</pre><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/22546862-ae9f7c10ccf4f2d6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容