我正在实现不同的条形图来分析不同基因的表达。我想做的是为每个基因设置相同的 y 尺度(在我的例子中为 0-100)。
我还想在 ggplot 中设置一个刻度填充,让我可以为每个基因设置最大值 100 和最小值 0。
我给你一些数据,以便你可以尝试一些脚本:
Stages TPH
00 9.96255848
04 9.778249598
08 10.01361333
12 28.5846484
16 66.26588384
20 41.51936636
24 30.02374287
28 24.32832801
32 23.88064848
36 23.20842877
40 21.95980567
44 25.21053631
48 24.98618594
52 22.19588764
72 20.17286473
提前感谢您的帮助!
干杯, 比阿特丽斯
我尝试了 ggplot 和scale_fill_distiller,但没能达到我想要的比例。
如果我理解正确的话,您希望 y 轴和条形填充的颜色比例范围从 0 到 100。这可以通过以下代码实现:
# load libraries
library(ggplot2)
# assign your data to the variable dat
dat <- structure(list(Stages = c("00", "04", "08", "12", "16", "20",
"24", "28", "32", "36", "40", "44",
"48", "52", "72"),
TPH = c(9.96255848, 9.778249598, 10.01361333,
28.5846484, 66.26588384, 41.51936636,
30.02374287, 24.32832801, 23.88064848,
23.20842877, 21.95980567,25.21053631,
24.98618594, 22.19588764, 20.17286473)),
row.names = c(NA, 15L),
class = "data.frame")
# plot
ggplot(dat, aes(x = Stages, y = TPH)) +
geom_col(aes(fill = TPH)) +
ylim(limits = c(0, 100)) +
scale_fill_distiller(palette = "RdYlBu",
limits = c(0, 100)) +
theme(legend.position = "none")