我一直在使用brewer.pal(11, "Spectral")[1:3]為我的條形圖著色。但是,我無法在比例尺上選擇不連續的顏色,例如我想要光譜比例尺上的第一、第二和第八種顏色,但我不知道如何獲得它們......,只有陣列的選項允許我指出兩個值。
然后,這些顏色將成為我的條形圖的填充物,見下文
基本上,我想保持前兩個柱形條的色調相同,并使用比例光譜中的第 8 種顏色(應該是綠色調)來更改第三個。下面的代碼
library(readxl)
library(scales)
library(ggdark)
library(ggpubr)
library(ggplot2)
library(forcats)
library(reshape2)
library(RColorBrewer)
excel_pggb <- read_excel("/media/mat/Extreme SSD/TheUniversityOfFerrara/2°Year/pangenome_assembly_R.xlsx") # PGGB tab performance
## excel_mcCACTUS <- read_excel("/media/mat/Extreme SSD/TheUniversityOfFerrara/2°Year/pangenome_assembly_R.xlsx", 2) # mc-CACTUS tab performance
df_pggb <- data.frame(excel_pggb) # PGGB dataframe
## df_mcCACTUS <- data.frame(excel_HG005) # mc-CACTUS dataframe
df_pggb$tool_used <- factor(df_pggb$tool_used, levels=c('wfmash', 'seqwish', 'smoothxg')) # order of tools pggb
df_pggb$aspect <- factor(df_pggb$aspect, levels=c('real_timeH', 'cpu_timeH', 'peak_memGB')) # order of aspects pggb
## df_mcCACTUS$tool_used <- factor(df_mcCACTUS$tool_used, levels=c('', '', '', '')) # order of tools mc-CACTUS
## df_mcCACTUS$aspect <- factor(df_mcCACTUS$aspect, levels=c('real_timeH', 'cpu_timeH', 'peak_memGB')) # order of aspects pggb
df2 <- with(df_pggb, df_pggb[order(No_of_threads, tool_used, aspect),]) # collapse threads based on number used (PGGB)
## df3 <- with(df_mcCACTUS, df_mcCACTUS[order(No_of_threads, tool_used, aspect),]) # collapse threads based on number used (mc-CACTUS)
### PLOT performance of different tools of the PGGB builder
test_on_pggb <-
ggplot(df_pggb, aes(x=No_of_threads, y=value, fill=aspect)) geom_col(position='dodge', width=.6, alpha=.6, color='black')
ggplot(df2, aes(x=tool_used, y=value, fill=aspect)) geom_col(position='dodge', width=.6, alpha=.6, color='black') facet_wrap(~No_of_threads, scales='free', nrow=1) theme_bw()
theme(plot.title=element_text(face='bold.italic', hjust=.5), legend.title=element_text(face='italic'), legend.position='bottom', legend.direction='horizontal')
scale_fill_manual(values=brewer.pal(11, "Spectral")[1:8], labels=c('real_time_hours', 'CPU/h', 'RAM in GB')) ggtitle('PGGB_performance_by_tool')
guides(fill=guide_legend(title='execution_aspect', title.position='top', title.hjust=.5))
我嘗試了幾種數字組合以適合以逗號或列分隔的陣列,但不幸的是,它們都不起作用......
uj5u.com熱心網友回復:
用于c()指定向量中的索引:
brewer.pal(11, "Spectral")[c(1, 2, 8)]
[1] "#9E0142" "#D53E4F" "#ABDDA4"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/525502.html
