制作一个堆叠的ggplot条形图,使用非分类值。

huangapple go评论179阅读模式
英文:

Making a stacked ggplot bar plot with non-categorical values

问题

我想创建一个类似下面的堆叠条形图,但是使用数值而不是分类变量。

这是我想要的示例。
制作一个堆叠的ggplot条形图,使用非分类值。

这是我目前拥有的。
[![在此输入图片描述][2]][2]

图表的条形图部分是感兴趣区域(ROI)内特定细胞类型的总数(在数据框中为total_cd8)。我想将该总数分解为该ROI内每种组织类型中该特定细胞的数量(tumor_cd8、epi_cd8、stroma_cd8和necro_cd8),每种组织类型占据每个条形图上的一些空间。有没有人有关于如何做到这一点的想法?我想象中与条形图中的“fill”参数有关。

这是迄今为止的图表代码

sunburst <- ggplot() + 
  scale_x_continuous(name="x") +
  geom_rect(data=stroma_comp, mapping=aes(xmin=lower_lim, xmax=upper_lim,
                                          ymin=ymin,ymax=ymax,
                                          fill = stroma_bins), color='black', alpha=1) +
  geom_col(data = plot_sample,
           mapping = aes(x = row_id, y = total_cd8, fill = '#D3D3D3'),
           color='dark gray',
           width = 1,
           alpha=1,
           just = 1,
           position = position_dodge(0)) + # columns on outer level
  annotate("text", x = 1, y = -300, label = paste(sample_name, "\n", indication, "\n", pheno), size = 5,
           color = "black") +
  theme_void() +
  coord_polar() +
  geom_textpath(data = stroma_comp,
            mapping = aes(x=lower_lim + (upper_lim-lower_lim)/2, y = ymin/2,
                          label = stroma_bins), angle = 90, size = 4, color = "black") +
  scale_fill_manual(values = c("0-10%" = "#FF7100",
                               "10-20%" = "#eb8e00",
                               "20-30%" = "#d4a600",
                               "30-40%" = "#bbb908",
                               "40-50%" = "#a1ca3c",
                               "50-60%" = "#85d865",
                               "60-70%" = "#66e58e",
                               "70-80%" = "#41efb6",
                               "80-90%" = "#0df8dd",
                               "90-100%" = "#00ffff"), guide = "none") +
  scale_color_discrete(guide = "none") +
  theme(
    panel.background = element_rect(fill='transparent'),
    plot.background = element_rect(fill='transparent', color=NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.background = element_rect(fill='transparent'),
    legend.box.background = element_rect(fill='transparent')
  )

sunburst

以下是我正在使用的(略有截断)数据框。

dput(stroma_comp)
structure(list(stroma_bins = structure(2:10, levels = c("0-10%", 
"10-20%", "20-30%", "30-40%", "40-50%", "50-60%", "60-70%", "70-80%", 
"80-90%", "90-100%"), class = "factor"), n = c(2.09, 1.09, 5.09, 
8.09, 17.09, 23.09, 24.09, 28.09, 54.09), upper_lim = c(2.09, 
3.18, 8.27, 16.36, 33.45, 56.54, 80.63, 108.72, 162.81), lower_lim = c(0, 
2.09, 3.18, 8.27, 16.36, 33.45, 56.54, 80.63, 108.72), ymax = c(0, 
0, 0, 0, 0, 0, 0, 0, 0), ymin = c(-200, -200, -200, -200, -200, 
-200, -200, -200, -200)), row.names = c(NA, -9L), class = "data.frame")
dput(plot_sample)
structure(list(tumor_cd45 = c(2, 
15, 1, 1,

<details>
<summary>英文:</summary>

I&#39;d like to create a stacked bar plot similar to the one below, but using a numerical rather than categorical variable.

Here&#39;s the example of what I&#39;m looking for.
[![enter image description here][1]][1]

And here&#39;s what I have so far.
[![enter image description here][2]][2]

The bar plot portion of the graph is the total number of a particular cell type within a specific region of interest (ROI) containing multiple tissue types (total_cd8 in the dataframe). I&#39;d like to break that total number down into the number of that particular cell in each tissue type with that ROI (tumor_cd8, epi_cd8, stroma_cd8, and necro_cd8), with each tissue type taking up some space on each bar. Would anyone have an idea on how to do this? I imagine it has something to do with the &quot;fill&quot; parameter in the bar plot.

Here&#39;s the code for the chart so far

sunburst <- ggplot() +
scale_x_continuous(name="x") +
geom_rect(data=stroma_comp, mapping=aes(xmin=lower_lim, xmax=upper_lim,
ymin=ymin,ymax=ymax,
fill = stroma_bins), color='black', alpha=1) +
geom_col(data = plot_sample,
mapping = aes(x = row_id, y = total_cd8, fill = '#D3D3D3'),
epi_cd8, necro_cd8)),
color='dark gray',
width = 1,
alpha=1,
just = 1,
position = position_dodge(0)) + # columns on outer level
annotate("text", x = 1, y = -300, label = paste(sample_name, "\n", indication, "\n", pheno), size = 5,
color = "black") +
theme_void() +
coord_polar() +
geom_textpath(data = stroma_comp,
mapping = aes(x=lower_lim + (upper_lim-lower_lim)/2, y = ymin/2,
label = stroma_bins), angle = 90, size = 4, color = "black") +
scale_fill_manual(values = c("0-10%" = "#FF7100",
"10-20%" = "#eb8e00",
"20-30%" = "#d4a600",
"30-40%" = "#bbb908",
"40-50%" = "#a1ca3c",
"50-60%" = "#85d865",
"60-70%" = "#66e58e",
"70-80%" = "#41efb6",
"80-90%" = "#0df8dd",
"90-100%" = "#00ffff"), guide = "none") +
scale_color_discrete(guide = "none") +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)

sunburst


And here are the (slightly trunctaed) dataframes I&#39;m using.

dput(stroma_comp)
structure(list(stroma_bins = structure(2:10, levels = c("0-10%",
"10-20%", "20-30%", "30-40%", "40-50%", "50-60%", "60-70%", "70-80%",
"80-90%", "90-100%"), class = "factor"), n = c(2.09, 1.09, 5.09,
8.09, 17.09, 23.09, 24.09, 28.09, 54.09), upper_lim = c(2.09,
3.18, 8.27, 16.36, 33.45, 56.54, 80.63, 108.72, 162.81), lower_lim = c(0,
2.09, 3.18, 8.27, 16.36, 33.45, 56.54, 80.63, 108.72), ymax = c(0,
0, 0, 0, 0, 0, 0, 0, 0), ymin = c(-200, -200, -200, -200, -200,
-200, -200, -200, -200)), row.names = c(NA, -9L), class = "data.frame")
> dput(plot_sample)
structure(list(tumor_cd45 = c(2,
15, 1, 1, 9, 7, 4, 4, 2, 3, 2, 1, 8, 0, 3, 0, 0, 0, 1, 2,
3, 6, 2, 3, 4, 0, 2, 4, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 3, 0, 6, 4, 1, 1, 6, 3, 2, 8, 2, 3, 0, 0,
1, 2, 6, 0, 0, 0, 1, 0, 4, 0, 0, 0, 1, 2, 4, 0, 0, 0, 0,
6, 1, 4, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 2, 2, 0, 0, 0, 2,
0, 0, 0, 2, 3, 0, 1, 1, 0, 1, 3, 5, 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, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0), tumor_cd8 = c(0, 2, 0, 2, 3,
4, 5, 3, 0, 0, 0, 4, 6, 3, 2, 4, 0, 0, 0, 0, 1, 2, 3, 0,
0, 0, 0, 1, 4, 0, 2, 1, 5, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
1, 2, 0, 2, 0, 2, 4, 3, 1, 0, 3, 1, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 1, 1, 1, 1, 4, 0, 1, 1, 1, 2, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0,
0, 0, 0, 1, 2, 2, 0, 3, 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, 0, 0, 0, 3), tumor_epi = c(151, 136, 338, 131, 379, 221,
251, 247, 58, 102, 276, 290, 266, 315, 255, 282, 31, 23,
138, 94, 113, 246, 232, 50, 262, 217, 60, 239, 233, 218,
179, 249, 207, 10, 0, 163, 6, 13, 84, 17, 154, 163, 177,
152, 74, 32, 141, 154, 47, 213, 170, 194, 208, 194, 156,
193, 3, 9, 55, 78, 144, 18, 25, 56, 54, 103, 99, 73, 85,
151, 165, 58, 95, 172, 128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, 3, 1, 5, 1, 2, 2, 0, 2, 2, 2,
2, 8, 1, 7, 6, 13, 0, 19, 5, 6, 19, 12, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 5, 1, 0, 1, 0, 0,
0, 5, 1, 0, 0, 3, 3, 0, 0, 0, 0, 0, 6, 0, 4, 2, 2, 0, 4,
7, 3, 2, 10, 0, 1, 6, 6, 3, 1), stroma_cd8 = c(0, 3, 0, 1,
1, 2, 2, 19, 1, 2, 4, 1, 2, 6, 9, 24, 0, 1, 1, 1, 0, 1, 1,
3, 4, 4, 4, 5, 5, 10, 9, 10, 9, 0, 0, 0, 0, 1, 1, 1, 1, 2,
2, 1, 1, 3, 0, 5, 0, 8, 11, 13, 15, 13, 19, 21, 0, 0, 0,
0, 1, 1, 1, 1, 2, 1, 0, 3, 2, 3, 3, 4, 1, 5, 5, 5, 5, 5,
6, 18, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 4, 4, 4, 5,
5, 4, 6, 6, 6, 7, 8, 11, 16, 15, 16, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 5, 5, 6, 6, 6, 7, 5), stroma_epi = c(4, 4, 32, 26,
40, 29, 6, 44, 14, 1, 55, 57, 43, 63, 84, 61, 8, 6, 33, 18,
43, 32, 63, 14, 41, 35, 11, 39, 33, 50, 38, 89, 35, 6, 0,
44, 4, 9, 17, 2, 61, 37, 67, 24, 23, 14, 46, 50, 3, 20, 49,
42, 59, 44, 63, 45, 0, 2, 5, 17, 51, 4, 6, 39, 29, 19, 13,
17, 28, 27, 100, 13, 21, 29, 37, 22, 101, 13, 33, 77, 0,
18, 15, 2, 11, 17, 5, 7, 8, 12, 4, 0, 7, 13, 5, 35, 36, 44,
46, 43, 95, 57, 13, 103, 48, 57, 21, 60, 0, 0, 0, 0, 9, 0,
0, 2, 5, 0, 0, 0, 0, 0, 1, 0, 9, 1, 4, 18, 0, 0, 0, 0, 1,
0, 33, 1, 0, 0, 0, 2, 1, 2, 0, 13, 0, 26, 8, 4, 3, 4, 6,
5, 66, 2, 7, 7, 3, 2, 4, 31, 5, 11), stroma_stromal = c(11,
14, 57, 47, 122, 78, 112, 87, 63, 65, 269, 226, 272, 208,
235, 173, 124, 138, 173, 132, 187, 164, 386, 116, 285, 234,
38, 218, 289, 350, 184, 243, 149, 164, 2, 209, 23, 116, 317,
24, 456, 305, 401, 289, 236, 75, 266, 524, 178, 272, 397,
396, 340, 311, 412, 373, 6, 41, 380, 287, 525, 23, 80, 153,
386, 394, 425, 175, 386, 372, 593, 311, 374, 444, 337, 238,
351, 142, 314, 437, 52, 367, 475, 6, 441, 373, 169, 61, 174,
411, 185, 193, 99, 466, 279, 584, 651, 359, 578, 540, 330,
357, 358, 450, 669, 556, 181, 438, 48, 12, 10, 2, 82, 3,
1, 406, 250, 30, 8, 62, 3, 184, 425, 190, 95, 44, 8, 297,
41, 2, 147, 2, 11, 7, 179, 90, 14, 101, 222, 196, 56, 199,
40, 223, 15, 243, 442, 247, 315, 341, 146, 150, 436, 129,
144, 359, 182, 233, 258, 136, 463, 445), X = 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 1, 0, 0, 0), necro_stromal = c(5,
0, 0, 0, 0, 13, 37, 0, 27, 0, 0, 0, 55, 7, 0, 0, 0, 0, 0,
0, 0, 2, 0, 24, 0, 58, 2, 0, 0, 0, 0, 0, 0, 0, 6, 25, 0,
0, 13, 0, 0, 0, 0, 0, 112, 0, 33, 0, 40, 0, 0, 0, 0, 0, 0,
0, 0, 0, 30, 12, 0, 0, 2, 0, 0, 56, 38, 0, 27, 0, 0, 0, 21,
0, 0, 0, 0, 0, 0, 0, 3, 25, 8, 0, 40, 43, 0, 0, 1, 4, 3,
0, 5, 0, 5, 0, 0, 11, 0, 0, 0, 6, 0, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 19, 0, 0, 0, 12, 0, 0,
6, 29, 0, 0, 2, 0, 0, 10, 0, 2, 3, 0, 0, 4), cd8_density_stroma = c(0, 0.000496375474557704,
0, 8.66250791211816e-05, 3.42000322608904e-05, 0.000102341273597032,
0.000101820612109577, 0.000977239198967315, 8.32523211933494e-05,
9.45477096630444e-05, 9.98197407706786e-05, 2.41130827189272e-05,
5.56064091613561e-05, 0.00016209928341202, 0.00022325821531193,
0.000714865772543139, 0, 4.87952458674843e-05, 3.53501819959932e-05,
4.39054463547099e-05, 0, 2.33044457793335e-05, 1.99008218265272e-05,
0.000147189590657947, 8.50423158976891e-05, 0.000105147942866456,
0.000262167400426249, 0.000120183144883118, 0.000102353827281249,
0.000190855385591625, 0.000296765404484602, 0.000256587936319062,
0.000234733013079955, 0, 0, 0, 0, 5.27457799459669e-05, 1.76178332218036e-05,
0.000213458389211403, 1.68705402284055e-05, 4.70427305986847e-05,
3.46956854440584e-05, 2.30723264483166e-05, 2.20203526941317e-05,
0.00032322123141148, 0, 8.56054018556317e-05, 0, 0.000142265128879261,
0.000192940167379068, 0.000235125224538485, 0.00026426749274007,
0.000254201344993395, 0.000322169681358721, 0.000371150694085201,
0, 0, 0, 0, 1.60131369982462e-05, 0.000110941562818707, 8.25654212482013e-05,
4.10120040085133e-05, 3.10948019565844e-05, 1.67508022331895e-05,
0, 8.47661777119016e-05, 3.20447326009343e-05, 4.71906249833407e-05,
4.74441941501381e-05, 6.46275486982595e-05, 1.72485676806647e-05,
8.5156660775773e-05, 0.00010252161256064, 0.000118982796087141,
8.35024170993765e-05, 7.91537136957079e-05, 0.000110192289843276,
0.00026589031029089, 0, 0, 0, 0, 0, 0, 0, 0, 2.62181140278635e-05,
3.1895611888313e-05, 6.61221715228635e-05, 2.65548482370773e-05,
5.451585075346e-05, 5.43943549886517e-05, 8.46681573497675e-05,
5.51649905637043e-05, 6.56760549396277e-05, 6.51458887912956e-05,
5.50860353186291e-05, 8.14498564228402e-05, 8.16981102540834e-05,
8.59800321836158e-05, 0.000101425495052553, 0.00011037865735059,
0.000145318986715489, 0.000219438185579751, 0.000270984874473393,
0.000234959589784757, 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, 5.73265901746891e-05,
1.14626913542578e-05, 1.89009696998857e-05, 4.87762216699778e-05,
3.51218905562975e-05, 0.000127379446467775, 2.88816940481396e-05,
0.000505400482121736, 1.73106307573027e-05, 2.65873042724083e-05,
4.62641212063904e-05, 2.99107154227221e-05, 2.51822682185976e-05,
3.33586542198189e-05, 6.81114181426266e-05, 2.75809751469722e-05,
6.07216602948696e-05, 9.76476317700515e-05, 6.4262328737729e-05,
0.000181944173196006, 7.00765371617494e-05, 7.10887716699814e-05,
0.000232539026269027, 7.95752528552826e-05, 6.29873680672572e-05
), cd8_density_tumor = c(0, 5.57862025251641e-05, 0, 9.03805021853418e-05,
5.59504768155585e-05, 9.57967609639848e-05, 0.000126567455349236,
8.72291591307942e-05, 0, 0, 0, 8.91406535909941e-05, 0.000158153978265136,
7.22904771906207e-05, 4.45782667170612e-05, 0.000100531737239867,
0, 0, 0, 0, 5.90448963693577e-05, 5.19193192573534e-05, 7.92272486846837e-05,
0, 0, 0, 0, 3.04309970720451e-05, 0.000103409414871398, 0,
6.93865579856683e-05, 3.07149455524914e-05, 0.000175044242082098,
0, NaN, 0, 0, 0, 0, 0, 3.81245392363499e-05, 0, 0, 3.6790180241752e-05,
0.000172831253587167, 0, 8.74884526725332e-05, 0, 0.000212461355669594,
0.000143695138520802, 0.00010094414030218, 3.20365258426528e-05,
0, 9.09059733851491e-05, 3.7495987226317e-05, 0.000102000502536076,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000186975506825625, 0, 5.56806656806215e-05,
4.12350820853996e-05, 4.23090200135584e-05, 4.57522380061801e-05,
0.000222475086169189, 0, 5.26458842195289e-05, 9.71923973851902e-05,
7.68345304460515e-05, 8.10408931212117e-05, 6.16797929078748e-05,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000262787005455879,
0, 0, 0, 0, 0, 0.000128955271767271, 0, 0, 0, 0, 8.64454853460596e-05,
0.000168864823700185, 0.000137798534064745, 0, 0.000245267869180692,
NaN, NaN, NaN, NaN, 0, NaN, NaN, 0, 0, NaN, NaN, NaN, NaN,
0, 0, NaN, 0, 0, NaN, 0, NaN, NaN, 0, NaN, 0, NaN, 0, NaN,
NaN, 0, NaN, 0, 0, 0, NaN, 0, NaN, 0, 0, 0, 0, 0, 0, 0, 0,
NaN, 0, 0, 0, 0, 0, 0, 0, 0.000869663602812805), cd8_density_total = c(0,
0.000119084742581979, 0, 8.84108478978712e-05, 4.78159849825197e-05,
9.47745579897846e-05, 0.000143566863825392, 0.000404454076996279,
4.06191307640872e-05, 4.54984524952591e-05, 4.87643351540766e-05,
5.75507795677817e-05, 0.000112314017393495, 0.000113314500664771,
0.00012769863404695, 0.000377945962741339, 0, 2.72312213708469e-05,
1.84479932070061e-05, 2.61222961268419e-05, 2.5203831132547e-05,
3.62780208939271e-05, 4.51087695637509e-05, 0.000114221316633743,
4.5691654037522e-05, 5.32028795888328e-05, 0.00018359991214377,
7.97746272115383e-05, 0.000102264569697728, 0.000112574016585672,
0.000183472604329403, 0.000151804147510944, 0.000206025012537284,
0, 0, 0, 0, 3.51663243002276e-05, 1.21809928907584e-05, 0.000135816087632886,
2.30701988593005e-05, 3.15059804793923e-05, 2.34684085908325e-05,
2.78465306686199e-05, 4.55550646373068e-05, 0.000207097044515316,
5.36794830462874e-05, 5.78568984853077e-05, 0.000114005301114256,
0.000141022114749582, 0.000159928094866348, 0.000159512925186487,
0.000172224445984269, 0.000188632033443347, 0.000228614852329665,
0.000274638995451298, 0, 0, 0, 0, 1.1440675022067e-05, 8.08314151230211e-05,
6.21394007851599e-05, 3.18327048241649e-05, 2.30128995529106e-05,
2.3909134644006e-05, 3.6657209424331e-05, 6.55704812184831e-05,
4.70029551533454e-05, 4.51372550182113e-05, 4.52495112803909e-05,
5.85118438410447e-05, 6.31910148372465e-05, 6.0949480565122e-05,
8.78725815581787e-05, 0.000112699104098472, 7.98425232911552e-05,
7.88692403440172e-05, 9.69824788405706e-05, 0.000204047226635383,
0, 0, 0, 0, 0, 0, 0, 0, 2.32200892521716e-05, 2.61810719432006e-05,
5.64279320114293e-05, 2.25249383475262e-05, 7.20960341091528e-05,
4.86884127911919e-05, 6.96085801471008e-05, 4.54385380255808e-05,
5.62465106914627e-05, 5.85474471339415e-05, 6.75322523823125e-05,
6.73806795132649e-05, 6.74988481152822e-05, 7.73532285080713e-05,
8.90613135144463e-05, 0.000103911715424291, 0.000146333053958769,
0.00020329187873859, 0.000296302922392058, 0.000233772254767996,
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, 5.38702066862462e-05, 1.12817695108902e-05,
1.77088720372207e-05, 4.67438791098954e-05, 3.32103049836144e-05,
0.000121620434178869, 2.83353985069053e-05, 0.000494413522724037,
1.57758378138869e-05, 2.49561812195245e-05, 4.2859899850815e-05,
2.82953372627285e-05, 2.29495681117908e-05, 3.24184562926965e-05,
6.79080451998937e-05, 2.7048679312055e-05, 6.0428318946106e-05,
9.19641828813597e-05, 5.90281828996747e-05, 0.000176377071659383,
6.79695446595592e-05, 6.81299660904555e-05, 0.000219803692077052,
7.8105909207223e-05, 9.40943032584777e-05), stroma_percentage = c(0.155156673741843,
0.14394515686508, 0.27748495809641, 0.340204972181291, 0.349531724252201,
0.308687963512351, 0.31333289847462, 0.357436796113058, 0.487903882820892,
0.481222153951794, 0.488523961068037, 0.477340705364132,
0.448845212419021, 0.466029206626207, 0.467981437717268,
0.453167146606072, 0.548911077149507, 0.558071199083617,
0.52186416491709, 0.594967100796589, 0.560245815182973, 0.518899859100399,
0.566669682751772, 0.582011180901954, 0.53728139403555, 0.505981174129136,
0.560252455019995, 0.553146250867943, 0.555071083721745,
0.589839350022575, 0.505833721614182, 0.537842006308862,
0.564235295150888, 0.696161710194035, 0.658181851924192,
0.635069153045489, 0.66482912078284, 0.666713514071689, 0.69140130556369,
0.636264932639295, 0.683742148946021, 0.669731116336882,
0.676407117786211, 0.603461699690274, 0.689590296608449,
0.640728468272153, 0.63142366689141, 0.675855696383271, 0.683831586015505,
0.660841795224307, 0.651278531217818, 0.629958547011531,
0.65170499859272, 0.602921779098774, 0.674129572954314, 0.647470487997311,
0.768965525868043, 0.755065781062337, 0.795465121389254,
0.747529824054199, 0.714455576275902, 0.728594523723358,
0.752608051236869, 0.77618018416162, 0.740088313958131, 0.713671330816421,
0.737520752593233, 0.773545333627526, 0.733395964614399,
0.717365817376, 0.715306352404226, 0.724296000942031, 0.732710286525211,
0.715733566932701, 0.714260627291341, 0.789323525505967,
0.796808504318847, 0.711718617409012, 0.754388888046835,
0.767411292318815, 0.89886318571569, 0.807529320387861, 0.818623004332007,
0.875824179902595, 0.87808350660101, 0.865014195904043, 0.830977382548636,
0.861024028138524, 0.885650631753845, 0.820836171285171,
0.853388972440474, 0.848242028966888, 0.88165225480563, 0.895100471388067,
0.822134109515872, 0.823684325171932, 0.85642340641756, 0.898712846201345,
0.817294280261677, 0.827265786246002, 0.826198401717725,
0.899665033189086, 0.878095921230653, 0.836810045375521,
0.852058490258199, 0.823484261568532, 0.863234009786667,
0.837849803452409, 1, 0.9841897189232, 0.990990946320825,
1, 0.946818350104342, 0.994208489546719, 1, 0.967442910800989,
0.987013900341796, 0.996334301868119, 1, 0.990915693244734,
1, 0.974078528773216, 0.967086897718372, 0.965690087470299,
0.911296247611201, 0.985703531734446, 0.997732443283852,
0.982653062426745, 0.995798318580308, 1, 0.980986640605494,
1, 0.979253061637597, 1, 0.940678809820684, 0.968088678719835,
0.924132674065035, 0.93970715024371, 0.984216460360295, 0.936929285555533,
0.9583333335281, 0.945572816770242, 0.954788527909305, 0.981085058919197,
0.978260884612586, 0.911338127135066, 0.93865030331125, 0.926417680336157,
0.945993329241252, 0.911338403378695, 0.971815471903425,
0.997014113811181, 0.980700615838245, 0.995169082213181,
0.941796346868139, 0.918550324258927, 0.969402144411486,
0.969932982028966, 0.95837872128018, 0.945233561882892, 0.981535168342704,
0.933662436470643), cd8_density_ratio = c(NaN, 0.112387104892466,
NaN, 1.04335260760809, 1.63597731103724, 0.936052069678004,
1.2430435520563, 0.089260806589597, 0, 0, 0, 3.69677550689214,
2.84416815705924, 0.445964199649633, 0.199671338655009, 0.140630228920073,
NaN, 0, 0, 0, Inf, 2.227871872559, 3.98110436721141, 0, 0,
0, 0, 0.253205198629478, 1.0103131228034, 0, 0.233809456685739,
0.11970533764416, 0.745716334423204, NaN, NaN, NaN, NaN,
0, 0, 0, 2.25982918864438, 0, 0, 1.59455875956698, 7.84870505880795,
0, Inf, 0, Inf, 1.01005172281364, 0.523188829332026, 0.136253036676671,
0, 0.357614053487841, 0.116385834533471, 0.274822340794709,
NaN, NaN, NaN, NaN, 0, 0, 0, 0, 0, 0, Inf, 0, 1.7375918337043,
0.873798177073443, 0.891763908554768, 0.707937078347089,
12.8981774190201, 0, 0.513510106841031, 0.816860929322991,
0.920147381537597, 1.02384195683804, 0.559746902397624, 0,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 0, 0, 4.82037796024306,
0, 0, 0, 0, 0, 2.34097936112786, 0, 0, 0, 0, 0.783172104290842,
1.1620286345018, 0.627960597198177, 0, 1.0438725629602, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, 0, NaN, 0, 0, 0, NaN, 0, NaN, 0, 0, 0,
0, 0, 0, 0, 0, NaN, 0, 0, 0, 0, 0, 0, 0, 13.8069525604592
), stroma_bins = structure(c(2L, 2L, 3L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L), levels = c("0-10%", "10-20%", "20-30%", "30-40%",
"40-50%", "50-60%", "60-70%", "70-80%", "80-90%", "90-100%"
), class = "factor"), cd8_percent_bins = structure(c(1L,
2L, 1L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
4L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L), levels = c("0-2% CD8+ Cells",
"2-4% CD8+ Cells", "4-6% CD8+ Cells", "6-8% CD8+ Cells",
"8-10% CD8+ Cells", "10-15% CD8+ Cells", "15-20% CD8+ Cells",
">20% CD8+ Cells"), class = "factor"), row_id = 1:162), row.names = c(15305L,
15255L, 15284L, 15265L, 15339L, 15320L, 15317L, 15358L, 15321L,
15251L, 15274L, 15273L, 15333L, 15356L, 15282L, 15359L, 15239L,
15235L, 15267L, 15272L, 15360L, 15337L, 15296L, 15304L, 15310L,
15332L, 15258L, 15355L, 15325L, 15324L, 15266L, 15357L, 15354L,
15243L, 15301L, 15336L, 15361L, 15229L, 15231L, 15263L, 15286L,
15300L, 15314L, 15334L, 15319L, 15343L, 15335L, 15285L, 15290L,
15338L, 15297L, 15313L, 15340L, 15283L, 15295L, 15311L, 15222L,
15223L, 15302L, 15306L, 15275L, 15352L, 15371L, 15372L, 15240L,
15279L, 15318L, 15351L, 15237L, 15309L, 15342L, 15244L, 15322L,
15323L, 15329L, 15330L, 15377L, 15256L, 15281L, 15312L, 15219L,
15230L, 15236L, 15261L, 15280L, 15292L, 15353L, 15370L, 15247L,
15224L, 15233L, 15252L, 15260L, 15226L, 15242L, 15298L, 15327L,
15366L, 15299L, 15326L, 15367L, 15378L, 15294L, 15365L, 15328L,
15341L, 15259L, 15276L, 15218L, 15220L, 15228L, 15234L, 15250L,
15254L, 15264L, 15270L, 15271L, 15277L, 15278L, 15287L, 15289L,
15291L, 15293L, 15303L, 15315L, 15344L, 15345L, 15347L, 15349L,
15362L, 15368L, 15369L, 15373L, 15374L, 15376L, 15380L, 15381L,
15221L, 15245L, 15246L, 15257L, 15269L, 15288L, 15346L, 15350L,
15379L, 15225L, 15227L, 15238L, 15241L, 15253L, 15363L, 15364L,
15375L, 15331L, 15232L, 15268L, 15248L, 15249L, 15348L, 15308L,
15307L), class = "data.frame")


[1]: https://i.stack.imgur.com/NxFEm.png
[2]: https://i.stack.imgur.com/WGMJx.png
</details>
# 答案1
**得分**: 0
我可能不太明白您正在寻找哪些列,但似乎是融合的组合。
```R
cd8_cols = c("tumor_cd8", "stroma_cd8", "epi_cd8", "necro_cd8")
plot.m <- melt(plot_sample[,c('stroma_bins', cd8_cols)], id='stroma_bins')
ggplot(plot.m) + geom_col(aes(x=stroma_bins, y=value, fill=variable))

类似这样?

英文:

I might not understand exactly which columns you're looking for, but seems like a melt combination.

cd8_cols = c(&quot;tumor_cd8&quot;, &quot;stroma_cd8&quot;, &quot;epi_cd8&quot;, &quot;necro_cd8&quot;)
plot.m &lt;- melt(plot_sample[,c(&#39;stroma_bins&#39;, cd8_cols)], id=&#39;stroma_bins&#39;)
ggplot(plot.m) + geom_col(aes(x=stroma_bins, y=value, fill=variable))

Something like this?

答案2

得分: 0

以下是翻译好的部分:

你可以转换为长格式以绘制图表:

library(tidyverse)

plot_sample %>%
  select(row_id, stroma_bins, contains("_cd8")) %>%
  pivot_longer(contains("_cd8"), names_to = "细胞类型") %>%
  mutate(`细胞类型` = sub("_cd8", "", `细胞类型`)) %>%
  ggplot() +
  geom_col(aes(row_id, value, fill = `细胞类型`)) +
  geom_rect(aes(xmin = lower_lim, xmax = upper_lim, ymin = -50, ymax = 0),
            data = stroma_comp, color = "gray50",
            fill = c("#FF7100", "#eb8e00", "#d4a600", "#bbb908", "#a1ca3c",
                     "#85d865", "#66e58e", "#41efb6", "#0df8dd")) +
  annotate("text", x = 0, y = -100, 
           label = paste0(sample_name, "\n", indication, "\n", pheno), size = 5,
           color = "black", hjust = 0.5) +
  geom_textpath(aes(x = lower_lim + (upper_lim-lower_lim)/2, y = -25,
                label = stroma_bins), data = stroma_comp,
                angle = 90, size = 4, color = "black") +
  scale_y_continuous(limits = c(-100, 40)) +
  scale_fill_brewer(palette = "Set2") +
  coord_polar() +
  theme_void() +
  theme(legend.position = "bottom")

制作一个堆叠的ggplot条形图,使用非分类值。

英文:

You could pivot into long format to plot:

library(tidyverse)

plot_sample %&gt;%
  select(row_id, stroma_bins, contains(&quot;_cd8&quot;)) %&gt;%
  pivot_longer(contains(&quot;_cd8&quot;), names_to = &quot;Cell type&quot;) %&gt;%
  mutate(`Cell type` = sub(&quot;_cd8&quot;, &quot;&quot;, `Cell type`)) %&gt;%
  ggplot() +
  geom_col(aes(row_id, value, fill = `Cell type`)) +
  geom_rect(aes(xmin = lower_lim, xmax = upper_lim, ymin = -50, ymax = 0),
            data = stroma_comp, color = &quot;gray50&quot;,
            fill = c(&quot;#FF7100&quot;, &quot;#eb8e00&quot;, &quot;#d4a600&quot;, &quot;#bbb908&quot;, &quot;#a1ca3c&quot;,
                     &quot;#85d865&quot;, &quot;#66e58e&quot;, &quot;#41efb6&quot;, &quot;#0df8dd&quot;)) +
  annotate(&quot;text&quot;, x = 0, y = -100, 
           label = paste0(sample_name, &quot;\n&quot;, indication, &quot;\n&quot;, pheno), size = 5,
           color = &quot;black&quot;, hjust = 0.5) +
  geom_textpath(aes(x = lower_lim + (upper_lim-lower_lim)/2, y = -25,
                label = stroma_bins), data = stroma_comp,
                angle = 90, size = 4, color = &quot;black&quot;) +
  scale_y_continuous(limits = c(-100, 40)) +
  scale_fill_brewer(palette = &quot;Set2&quot;) +
  coord_polar() +
  theme_void() +
  theme(legend.position = &quot;bottom&quot;)

制作一个堆叠的ggplot条形图,使用非分类值。

huangapple
  • 本文由 发表于 2023年8月11日 03:01:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定