<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附帶并可用于繪圖的默認(rèn)配色方案。其中包括離散、連續(xù)和邊緣變量的方案。最后,我們將討論從十六進制值創(chuàng)建自定義配色方案</p><h1>默認(rèn)配色方案</h1><p>tidyplots帶有許多默認(rèn)配色方案。其中許多是從viridisLite和RColorBrewer軟件包改編而來的。您可以通過加載tidyplots庫并開始輸入colors_來訪問它們。自動完成將引導(dǎo)您選擇離散、連續(xù)和發(fā)散的方案。</p><p>讓我們看看tidyplotscolors_discrete_friendly的方案,它被設(shè)計用于色覺缺陷的人。當(dāng)在控制臺或腳本中運行colors_discrete_friendly時,該方案的預(yù)覽將呈現(xiàn)到RStudio桌面界面右下角的查看器窗格中。</p><p>本質(zhì)上,tidyplots配色方案只是一個十六進制顏色的字符向量,具有將預(yù)覽發(fā)送到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>提示:您可以直接從預(yù)覽中復(fù)制單個十六進制顏色以在腳本中使用它們。</p><h1>離散的</h1><p>離散配色方案適用于分類變量。整齊圖中的默認(rèn)方案由5-7種顏色組成。但是,如果圖中存在更多類別,整齊圖將自動填補顏色之間的空白,以準(zhǔn)確地提供為圖重新查詢的數(shù)字。</p><p>類似地,當(dāng)提供的顏色多于需要時,tidyplots將通過嘗試從提供的顏色向量中均勻采樣來選擇所需數(shù)量的顏色。</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>連續(xù)的</h1><p>連續(xù)配色方案適用于連續(xù)變量。tidyplots中的默認(rèn)方案通常由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>這是一個連續(xù)配色的用例。</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>中心配色方案適用于中間有中心點的連續(xù)變量。一個經(jīng)典的例子是用于基因表達熱圖的藍(lán)-白-紅漸變。</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>當(dāng)然,您也可以使用new_color_scheme()函數(shù)構(gòu)建自定義配色方案。</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()函數(shù)的輸入。</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>除了創(chuàng)建新方案之外,你還可以以與處理常規(guī)字符串完全相同的方式對現(xiàn)有方案進行子集劃分和連接。</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>
tidyplots學(xué)習(xí)超詳細(xì)注釋版-基于Cursor-(13)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 前言 Google Play應(yīng)用市場對于應(yīng)用的targetSdkVersion有了更為嚴(yán)格的要求。從 2018 年...
- """1.個性化消息: 將用戶的姓名存到一個變量中,并向該用戶顯示一條消息。顯示的消息應(yīng)非常簡單,如“Hello ...