我正在使用這篇 biostars 帖子中的代碼讓自己更加熟悉在 ggplot 中創建繪圖。雖然我在設定圖例變數上有點卡住了
有沒有辦法設定顏色并控制圖例中的中斷/點數(在numDEInCat下)
term <-c("snoRNA binding", "preprophase band", "kinesin complex", "microtubule motor activity", "DNA replication")
fc <-runif(5, 1.00, 5.00)
padj_BH <-runif(5, 0.001, 0.05)
numDEInCat <-runif(5, 30, 300)
ggdata <- data.frame(term,fc,padj_BH, numDEInCat)
gg1 <- ggplot(ggdata,
aes(x = term, y = fc, size = numDEInCat, color = padj_BH))
expand_limits(y = 1)
geom_point(shape = 16,inherit.aes = T)
scale_size(range = c(2.5,12.5))
scale_color_gradient(low= "#ff0303",
high="#1e00b3") #colour for p value
xlab('') ylab('Fold Enrichment') #lavel fold enrichment axis
labs(
title = "Gene Ontology all",
subtitle = 'BH-adjusted',
caption = '',
color="Adjusted P-value", #label the aacolor
size="count") #label dot size
theme_bw(base_size = 24)
theme(
legend.position = 'right',
legend.background = element_rect(),
plot.title = element_text(angle = 0, size = 16, face = 'bold', vjust = 1),
plot.subtitle = element_text(angle = 0, size = 14, face = 'bold', vjust = 1),
plot.caption = element_text(angle = 0, size = 12, face = 'bold', vjust = 1),
axis.text.x = element_text(angle = 0, size = 12, face = 'bold', hjust = 1.10),
axis.text.y = element_text(angle = 0, size = 12, face = 'bold', vjust = 0.5),
axis.title = element_text(size = 12, face = 'bold'),
axis.title.x = element_text(size = 12, face = 'bold'),
axis.title.y = element_text(size = 12, face = 'bold'),
axis.line = element_line(colour = 'black'),
#Legend
legend.key = element_blank(), # removes the border
legend.key.size = unit(1, "cm"), # Sets overall area/size of the legend
legend.text = element_text(size = 14, face = "bold"), # Text size
title = element_text(size = 14, face = "bold"))
coord_flip()
gg1

uj5u.com熱心網友回復:
我想,你要尋找的是guides(size = guide_legend(override.aes(BLABLA)))與scale_size(breaks = c(BLABLA))
gg1
guides(size = guide_legend(override.aes = list(colour = "red")))
scale_size(limits = c(1, 1000), breaks = c(10, 500, 1000))

由reprex 包(v2.0.1)于 2021 年 11 月 18 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/364784.html
標籤:ggplot2
上一篇:ggplot可視化改進
