[英]How to plot bar graph for certain values from the column in ggplot2? Values will be selected automatically from the data frame
[英]ggplot2: Bar Plot - How to graph values which are close to 0?
我想防止 label 堆疊在這里看到:示例圖
繪制的數據:
allele_count allele frequency population
<int> <chr> <dbl> <chr>
1 1865 G 0.894 gnomADg:oth
2 4801 G 0.925 gnomADg:eas
3 894 G 0.980 gnomADg:ami
4 3867 G 0.801 gnomADg:sas
5 10175 G 0.968 gnomADg:fin
6 273 G 0.864 gnomADg:mid
7 21 T 0.00138 gnomADg:amr
8 13046 G 0.856 gnomADg:amr
9 2901 G 0.836 gnomADg:asj
10 4 C 0.0000264 gnomADg:ALL
11 21 T 0.000138 gnomADg:ALL
用於生成圖表的代碼:
graphPREPdata2[1:11, ] %>% ggplot(aes(population, frequency)) +
geom_col(aes(fill = allele), width = .8, alpha = .5) +
theme_bw(base_size = 15) + ylim(0,1) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = paste0('Variant ID: ', names(ancesA_graphData[77])),
subtitle = paste0('Ancestral Allele: ', attr(graphPREPdata2, 'Ancestral_Allele'))) +
xlab('Population Ancestry')+ylab('Allele Frequency') +
geom_text(aes(label = mockLabels[1:11], angle = 35), size = 4)
在我當前的圖表中,有些值太小而無法看到,因此在它們當前的表示中令人困惑且在視覺上沒有吸引力。
我想了解如何直觀地表示任意小值的值。
(我已經刪除了依賴於我們沒有可用數據的 plot 的組件。)
刪除ylim(0,1)
並添加scale_y_sqrt()
。
graphPREPdata2[1:11, ] %>% ggplot(aes(population, frequency)) +
geom_col(aes(fill = allele), width = .8, alpha = .5) +
theme_bw(base_size = 15) + scale_y_sqrt() + ## CHANGE
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
# labs(title = paste0('Variant ID: ', names(ancesA_graphData[77])),
# subtitle = paste0('Ancestral Allele: ', attr(graphPREPdata2, 'Ancestral_Allele'))) +
xlab('Population Ancestry')+ylab('Allele Frequency')
# geom_text(aes(label = mockLabels[1:11], angle = 35), size = 4)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.