다음 데이터 세트가 있습니다.
structure(list(Isodecoder = c("Val", "Leu", "Ile", "Arg", "Ser",
"Ala"), Anticodon = c("AAC", "AAG", "AAT", "ACG", "AGA", "AGC"
), baseMean = c(16330.2876073118, 280025.429470444, 47222.9145508434,
639520.228162813, 591.699871418142, 194550.678700214), log2FC = c(0.241812205124871,
0.062182487534649, -0.912898805851376, 0.414430653693951, -0.547252664766089,
-0.576581451007797), lfcSE = c(0.330123826005643, 0.0835105091511506,
0.193443262487333, 0.258705563545134, 0.211263611125761, 0.249830083859411
), stat = c(0.732489405719955, 0.744606734729653, -4.71920703834881,
1.60193947132354, -2.59037825705024, -2.30789439806721), pvalue = c(0.463869906720502,
0.45650949539292, 2.36765754572021e-06, 0.109168994996796, 0.00958705250629343,
0.0210050107216242), FDR = c(0.585940934804845, 0.585940934804845,
1.7165121174307e-05, 0.201542759994085, 0.030678568020139, 0.0591953931677063
), Label = c("Val-AAC", "Leu-AAG", "Ile-AAT", "Arg-ACG", "Ser-AGA",
"Ala-AGC"), wobble = c("AT_wobble", "AT_wobble", "AT_wobble",
"AT_wobble", "AT_wobble", "AT_wobble")), row.names = c(NA, 6L
), class = "data.frame")
그리고 나는 이것을 더 큰 루프 내에서 막대 그래프로 플로팅하고 있습니다. 내 막대 그래프 기능은 다음과 같습니다.
tRNA_barplot <- ggplot(data = df2, aes(x = Label, y = log2FC, fill = wobble, label = ifelse(FDR < 0.05, "*", "ns")))+
geom_bar(stat = "identity")+
geom_text(vjust = 0, nudge_y = ifelse(df2$log2FC < 0, -1, 1), size = ifelse(df2$FDR < 0.05, 6, 4))+
xlab("Isoacceptor")+
ylab(expression(paste(Log[2],"FC",sep="")))+
#ylim(c(-5, 5))+
theme_bw()+
theme(axis.text.x = element_text(size = 12, angle = 45, hjust = 1), plot.margin = margin(0.5,0.5,0.5,2, "cm"), axis.title = element_text(size = 12))+
ggtitle(iso, "Fed vs Starved - tRNA LFCs")
나는 흔들림 위치에 따라 색칠하기 위해 fill = wobble 을 사용했습니다. AT_wobble과 GC_wobble이 모두 있는 막대 그림에서 ... AT_wobble은 빨간색으로, GC_wobble은 파란색/청록색으로 표시됩니다. GC_wobble이 단독으로 표시되는 막대 그래프에서 파란색/청록색으로 유지되도록 하려면 어떻게 해야 합니까?
그런데 ... 파란색과 빨간색으로 지정되지 않은 경우 표준 R 색상 출력을 의미합니다.
내가 말하는 것의 예는 다음과 같습니다.
Leu는 완벽하지만 Pro와 같은 플롯이 GC_wobble에 대해 파란색/청록색으로 유지되기를 바랍니다.
Also, I've specified that all FDR > 0.05 should have ns printed ontop of the barplot [ifelse(FDR < 0.05, "*", "ns")]. Is there a way to print the actual FDR number to 4 decimal places? I've tried numerous ways but they're all really messy.
Thanks!
Here is one approach to the two part question:
Part 1: Using the scales
package you can determine the code for any default ggplot colour. I've set this out explicitly in a separate line to make it obvious, you could simplify by including this directly in the call to scale_fill_manual
Part 2: print the actual FDR number using a call to geom_text
. Note adjustment to y scale to allow FDR text to avoid clashing with the plot boundary.
몇 가지 다른 점 :
A)는 geom_col()
보다 간단 geom_bar(stat = "identity")
호출) 나 expression()
포함 할 필요가 없습니다 paste
, 체크 아웃 ?plotmath
) C가 사용 별표 크기를 조정 ifelse
에 대한 호출에 대한 조건문size
library(ggplot2)
col_GC_wobble <- scales::hue_pal()(2)[[2]]
scales::hue_pal()(2)[2]
#> [1] "#00BFC4"
ggplot(df2, aes(x = Label, y = log2FC, fill = wobble))+
geom_col()+
geom_text(aes(label = ifelse(FDR < 0.05, "*", round(FDR, 4))),
vjust = ifelse(df2$log2FC < 0, 1, -0.2),
size = ifelse(df2$FDR < 0.05, 10, 4))+
scale_fill_manual(values = col_GC_wobble)+
scale_y_continuous(expand = expansion(mult = 0.1))+
xlab("Isoacceptor")+
ylab(expression(Log[2]~FC))+
theme_bw()+
theme(axis.text.x = element_text(size = 12, angle = 45, hjust = 1),
plot.margin = margin(0.5,0.5,0.5,2, "cm"),
axis.title = element_text(size = 12))+
ggtitle("Fed vs Starved - tRNA LFCs")
2021-09-18에 reprex 패키지 ( v2.0.0)에 의해 생성됨
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다