如何创建一个单行 barplot/heatmap,我可以在其中绘制时间点的值?
How do I create a one-row barplot/heatmap in which I can plot the values of my timepoints?
很难解释我面临的情节挑战。如果有人对如何编写问题有更好的想法,我会更改它。
我原来的R数据框如下:
structure(list(Gene = c("Actl6a_1", "Actl6a_1", "Actl6a_1", "Actl6a_2",
"Actl6a_2", "Actl6a_2", "Cebpa_1", "Cebpa_1", "Cebpa_1", "Cebpa_2",
"Cebpa_2", "Cebpa_2", "Cebpa_3", "Cebpa_3", "Cebpa_3"), Time.point = c("T1",
"T2", "T3", "T1", "T2", "T3", "T1", "T2", "T3", "T1", "T2", "T3",
"T1", "T2", "T3"), Lin_score = c(6.62286740798228, 0.725529973292214,
1.45277082126036, 7.58080470281066, 2.23746335327345, 0.912864932488962,
4.57106792646335, 3.45482367414755, 2.00747227550368, 9.5569448291242,
1.19180459071481, 4.84044979652114, 1.77470104454199, 2.36007115400718,
7.3450372293307), Deple_Score = c(24.4059246224385, 1.4681178665796,
3.80340636569322, 5.35461394207936, 1.54776909412289, 1.35977608722976,
3.94031620390256, 1.03991947913739, 1.53296584765398, 3.91215174555478,
0.180873007077615, 3.7132386172666, 1.61370679951173, 2.77858577375842,
4.07592722173201)), class = "data.frame", row.names = c(NA, -15L)) here
我已经用以下方法缩放了 df:
df <- as.data.frame(apply(table_stack[, 3:4], 2, scale))
df$Gene <- table_stack$Gene
df$Time.point <- table_stack$Time.point
所以,我最终得到以下 R 数据框
dput(df)
structure(list(Lin_score = c(1.00804079166467, -1.07987355614156,
-0.822398616374401, 1.34719232306691, -0.544583277782937, -1.01354882002391,
0.281614396070452, -0.11358469434566, -0.626010138033161, 2.04683201109546,
-0.914792030026438, 0.376987312706364, -0.708421293620525, -0.501174775363001,
1.26372036710774), Deple_Score = c(3.49732264514564, -0.443296466495975,
-0.0421036851306225, 0.224387278312042, -0.429612719271858, -0.461909130332555,
-0.0185831484567453, -0.51685915568804, -0.432155855002777, -0.0234216844168561,
-0.66443974094702, -0.0575941265876234, -0.418284897706412, -0.21816356973797,
0.00471425631676927), Gene = c("Actl6a_1", "Actl6a_1", "Actl6a_1",
"Actl6a_2", "Actl6a_2", "Actl6a_2", "Cebpa_1", "Cebpa_1", "Cebpa_1",
"Cebpa_2", "Cebpa_2", "Cebpa_2", "Cebpa_3", "Cebpa_3", "Cebpa_3"
), Time.point = c("T1", "T2", "T3", "T1", "T2", "T3", "T1", "T2",
"T3", "T1", "T2", "T3", "T1", "T2", "T3")), row.names = c(NA,
-15L), class = "data.frame")
我想绘制一个连续颜色缩放 "barplot" 或 "tile",我可以在其中指示我的时间点落入的位置。对于每个基因。理想情况下,每个基因都有自己的 "heatmap" 或自己的条形图。但是对于每个基因,我希望绘制两个分数。
类似于:
到目前为止我做的最好的是:
ggplot(df, aes(x = Time.point, y =1 , fill = Lin_score)) +
geom_tile+
ylab("")
所以,我不知道如何在 R 中编码这个简单的图,它看起来像我附加的图像。我需要它,因为我必须以编程方式对(数百)不同基因进行编程。我已经根据列缩放了数据,我知道我应该只根据每个基因的分数进行缩放,否则会产生误导。
非常感谢
这对你有用吗?
library(tidyverse)
df <- structure(list(Lin_score = c(1.00804079166467, -1.07987355614156,
-0.822398616374401, 1.34719232306691, -0.544583277782937, -1.01354882002391,
0.281614396070452, -0.11358469434566, -0.626010138033161, 2.04683201109546,
-0.914792030026438, 0.376987312706364, -0.708421293620525, -0.501174775363001,
1.26372036710774), Deple_Score = c(3.49732264514564, -0.443296466495975,
-0.0421036851306225, 0.224387278312042, -0.429612719271858, -0.461909130332555,
-0.0185831484567453, -0.51685915568804, -0.432155855002777, -0.0234216844168561,
-0.66443974094702, -0.0575941265876234, -0.418284897706412, -0.21816356973797,
0.00471425631676927), Gene = c("Actl6a_1", "Actl6a_1", "Actl6a_1",
"Actl6a_2", "Actl6a_2", "Actl6a_2", "Cebpa_1", "Cebpa_1", "Cebpa_1",
"Cebpa_2", "Cebpa_2", "Cebpa_2", "Cebpa_3", "Cebpa_3", "Cebpa_3"
), Time.point = c("T1", "T2", "T3", "T1", "T2", "T3", "T1", "T2",
"T3", "T1", "T2", "T3", "T1", "T2", "T3")), row.names = c(NA,
-15L), class = "data.frame")
df <- df %>%
pivot_longer(cols =c('Lin_score','Deple_Score'),values_to = 'Score')
df %>%
ggplot(aes(x = Score, fill = Score)) +
geom_point(y = 1,color = 'green') +
geom_point(y = 0.9,color = 'green',fill = 'green',pch = 25) +
geom_text(y = 1.2, aes(label = Time.point),color = 'green') +
ylim(0,1.5) +
geom_tile(data = tibble(Score = seq(min(df$Score),max(df$Score),0.01)),aes(y = 0.5),height = 0.5) +
facet_wrap(Gene ~ name) +
theme_void()
您显然需要稍微调整一下比例才能完全按照您的意愿获得它...
很难解释我面临的情节挑战。如果有人对如何编写问题有更好的想法,我会更改它。
我原来的R数据框如下:
structure(list(Gene = c("Actl6a_1", "Actl6a_1", "Actl6a_1", "Actl6a_2",
"Actl6a_2", "Actl6a_2", "Cebpa_1", "Cebpa_1", "Cebpa_1", "Cebpa_2",
"Cebpa_2", "Cebpa_2", "Cebpa_3", "Cebpa_3", "Cebpa_3"), Time.point = c("T1",
"T2", "T3", "T1", "T2", "T3", "T1", "T2", "T3", "T1", "T2", "T3",
"T1", "T2", "T3"), Lin_score = c(6.62286740798228, 0.725529973292214,
1.45277082126036, 7.58080470281066, 2.23746335327345, 0.912864932488962,
4.57106792646335, 3.45482367414755, 2.00747227550368, 9.5569448291242,
1.19180459071481, 4.84044979652114, 1.77470104454199, 2.36007115400718,
7.3450372293307), Deple_Score = c(24.4059246224385, 1.4681178665796,
3.80340636569322, 5.35461394207936, 1.54776909412289, 1.35977608722976,
3.94031620390256, 1.03991947913739, 1.53296584765398, 3.91215174555478,
0.180873007077615, 3.7132386172666, 1.61370679951173, 2.77858577375842,
4.07592722173201)), class = "data.frame", row.names = c(NA, -15L)) here
我已经用以下方法缩放了 df:
df <- as.data.frame(apply(table_stack[, 3:4], 2, scale))
df$Gene <- table_stack$Gene
df$Time.point <- table_stack$Time.point
所以,我最终得到以下 R 数据框
dput(df)
structure(list(Lin_score = c(1.00804079166467, -1.07987355614156,
-0.822398616374401, 1.34719232306691, -0.544583277782937, -1.01354882002391,
0.281614396070452, -0.11358469434566, -0.626010138033161, 2.04683201109546,
-0.914792030026438, 0.376987312706364, -0.708421293620525, -0.501174775363001,
1.26372036710774), Deple_Score = c(3.49732264514564, -0.443296466495975,
-0.0421036851306225, 0.224387278312042, -0.429612719271858, -0.461909130332555,
-0.0185831484567453, -0.51685915568804, -0.432155855002777, -0.0234216844168561,
-0.66443974094702, -0.0575941265876234, -0.418284897706412, -0.21816356973797,
0.00471425631676927), Gene = c("Actl6a_1", "Actl6a_1", "Actl6a_1",
"Actl6a_2", "Actl6a_2", "Actl6a_2", "Cebpa_1", "Cebpa_1", "Cebpa_1",
"Cebpa_2", "Cebpa_2", "Cebpa_2", "Cebpa_3", "Cebpa_3", "Cebpa_3"
), Time.point = c("T1", "T2", "T3", "T1", "T2", "T3", "T1", "T2",
"T3", "T1", "T2", "T3", "T1", "T2", "T3")), row.names = c(NA,
-15L), class = "data.frame")
我想绘制一个连续颜色缩放 "barplot" 或 "tile",我可以在其中指示我的时间点落入的位置。对于每个基因。理想情况下,每个基因都有自己的 "heatmap" 或自己的条形图。但是对于每个基因,我希望绘制两个分数。
类似于:
到目前为止我做的最好的是:
ggplot(df, aes(x = Time.point, y =1 , fill = Lin_score)) +
geom_tile+
ylab("")
所以,我不知道如何在 R 中编码这个简单的图,它看起来像我附加的图像。我需要它,因为我必须以编程方式对(数百)不同基因进行编程。我已经根据列缩放了数据,我知道我应该只根据每个基因的分数进行缩放,否则会产生误导。
非常感谢
这对你有用吗?
library(tidyverse)
df <- structure(list(Lin_score = c(1.00804079166467, -1.07987355614156,
-0.822398616374401, 1.34719232306691, -0.544583277782937, -1.01354882002391,
0.281614396070452, -0.11358469434566, -0.626010138033161, 2.04683201109546,
-0.914792030026438, 0.376987312706364, -0.708421293620525, -0.501174775363001,
1.26372036710774), Deple_Score = c(3.49732264514564, -0.443296466495975,
-0.0421036851306225, 0.224387278312042, -0.429612719271858, -0.461909130332555,
-0.0185831484567453, -0.51685915568804, -0.432155855002777, -0.0234216844168561,
-0.66443974094702, -0.0575941265876234, -0.418284897706412, -0.21816356973797,
0.00471425631676927), Gene = c("Actl6a_1", "Actl6a_1", "Actl6a_1",
"Actl6a_2", "Actl6a_2", "Actl6a_2", "Cebpa_1", "Cebpa_1", "Cebpa_1",
"Cebpa_2", "Cebpa_2", "Cebpa_2", "Cebpa_3", "Cebpa_3", "Cebpa_3"
), Time.point = c("T1", "T2", "T3", "T1", "T2", "T3", "T1", "T2",
"T3", "T1", "T2", "T3", "T1", "T2", "T3")), row.names = c(NA,
-15L), class = "data.frame")
df <- df %>%
pivot_longer(cols =c('Lin_score','Deple_Score'),values_to = 'Score')
df %>%
ggplot(aes(x = Score, fill = Score)) +
geom_point(y = 1,color = 'green') +
geom_point(y = 0.9,color = 'green',fill = 'green',pch = 25) +
geom_text(y = 1.2, aes(label = Time.point),color = 'green') +
ylim(0,1.5) +
geom_tile(data = tibble(Score = seq(min(df$Score),max(df$Score),0.01)),aes(y = 0.5),height = 0.5) +
facet_wrap(Gene ~ name) +
theme_void()
您显然需要稍微调整一下比例才能完全按照您的意愿获得它...