我需要使用ggplot2在不同时间点可视化参数的变化。有4个时间点 - 0,3,12,24,并且在每个时间点,参数都有一个值,对于0点总是0,对于其他点则更改。
数据示例如下:
0 3 12 24
0 -2.67 1.56 3.61
0 1.83 3.11 3.1
0 0 0 1.1
0 0 0.72 0.53
0 0.4 -0.59 -0.76
0 0.62 -1.17 -1.65
0 0 0 0
0 -0.54 0 0
真实数据表称为LFC_cglab
。这是我的代码。
LFC_data_cglab<-cbind("gene"=rownames(LFC_cglab), LFC_cglab)
LFC_plotting_cglab<-melt(LFC_data_cglab, id.vars=c("gene"))
ggplot(data=LFC_plotting_cglab, aes(x=LFC_plotting_cglab$variable,
y=LFC_plotting_cglab$value,
group=LFC_plotting_cglab$gene,
colour=LFC_plotting_cglab$value)) +
geom_line() + scale_colour_gradient2(low = "green", mid = "yellow", high = "red",space = "Lab", na.value = "grey50", guide = "colourbar")
然而,在每个时间点之间颜色变化是离散的(这是有道理的)。我的问题是如何让它顺利进行?
谢谢
修改
数据集很大,因此以下是可重复示例的前50个观测值。
LFC_cglab <-
structure(list(`0` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `3` = c(NA,
NA, NA, -2.67869050939217, 1.83828953009858, 0, 0, 0.402748334498583,
0.627889272250883, 0, -0.544096095464866, -0.503121270644812,
0, 0, -1.26254881431947, 0, 0, 0, -1.10460896511504, 0, 0, 0,
0, 0, 0.624270679732113, 0, 0, 0, 0, 0, 0, 0, 0.499680203025943,
0, -0.700578611713783, 0, 0, 0, -0.896918417303839, 0, 0, 0,
0, 0, -0.987875379404733, 1.22467128314127, 0, 0, 1.14244275888976,
0), `12` = c(NA, NA, NA, 1.56000945272272, 3.11145262697241,
0, 0.728432311767462, -0.594107423019661, -1.17085668148238,
0, 0, -0.465471298898374, 0, 3.7551551167723, -0.4835241851924,
0, 0, -1.08635818109412, -0.854907365300897, 0, -2.49696212308684,
0, 0, 0, 0.418181856929939, 0, -0.825115910481231, 0, 0, 0, 0,
0.686462596309358, -0.589495768027921, -1.79419577859922, 0,
0.832069758788764, 0, 0, 0, 0.847868142370709, -1.33948677194486,
-0.937182676754619, -0.699909268338168, 2.22098970217753, -1.63337340477311,
0, 1.95593608100319, 0, -0.964821766122203, 0), `24` = c(NA,
NA, NA, 3.61874657573019, 3.10598113292214, 1.10880257805689,
0.53564534166384, -0.764431831579815, -1.65318495019956, 0, 0,
0, 0, 3.90245218864281, -0.682125403622271, 0, 0, -0.893924902802382,
-0.522869511436013, -0.430645964749997, -2.95955717487241, 0,
0, 0, 0.546114428096909, 0, 0, 0, 0, 0, 0, 0.467524925418611,
-0.787262866421737, -1.74888323047216, 0, 0.847433254520968,
0, -0.87257033703903, 0.426058169799006, 0.700216555893704, 0,
0, -0.754165109134996, 2.13267528744482, -2.25593650440977, 0,
2.67188332100762, 0, -1.29524088711605, 0)), .Names = c("0",
"3", "12", "24"), row.names = c("CAGL0A00105g", "CAGL0A00110g",
"CAGL0A00116g", "CAGL0A00132g", "CAGL0A00154g", "CAGL0A00165g",
"CAGL0A00187g", "CAGL0A00209g", "CAGL0A00231g", "CAGL0A00253g",
"CAGL0A00275g", "CAGL0A00297g", "CAGL0A00319g", "CAGL0A00341g",
"CAGL0A00363g", "CAGL0A00385g", "CAGL0A00407g", "CAGL0A00429g",
"CAGL0A00451g", "CAGL0A00473g", "CAGL0A00495g", "CAGL0A00517g",
"CAGL0A00539g", "CAGL0A00561g", "CAGL0A00583g", "CAGL0A00605g",
"CAGL0A00627g", "CAGL0A00649g", "CAGL0A00671r", "CAGL0A00715g",
"CAGL0A00737g", "CAGL0A00781g", "CAGL0A00803g", "CAGL0A00825g",
"CAGL0A00847g", "CAGL0A00869g", "CAGL0A00891g", "CAGL0A00913g",
"CAGL0A00935g", "CAGL0A00957g", "CAGL0A00979g", "CAGL0A01001g",
"CAGL0A01023g", "CAGL0A01045g", "CAGL0A01067g", "CAGL0A01089g",
"CAGL0A01111g", "CAGL0A01133g", "CAGL0A01155g", "CAGL0A01177g"
), class = "data.frame")