简体   繁体   English

R:分组多个条形图

[英]R: grouped multiple bar plots

Hi I have a data table that I made into long form so that I have columnes for ID, Cluster.membership, Enrichment, Stimulation (UNS or 3S), cytokine.measured (test), values.嗨,我有一个数据表,我把它做成了长格式,这样我就有了 ID、Cluster.membership、Enrichment、Stimulation(UNS 或 3S)、cytokine.measured(测试)、值的列。 I got stuck on the bar plot visualisation我卡在plot可视化上吧

在此处输入图像描述

I want to plot bar graph for each individual ID, compare its UNS vs 3S, for each cytokine measured, under each cluster.我想为每个单独的 ID 绘制 plot 条形图,比较每个集群下测量的每个细胞因子的 UNS 与 3S。 However my try on the bar chart was close but not good.然而,我在条形图上的尝试很接近但并不好。 You see I have stimulation conditions on X axis, and I have clusters and cytokine measured in groups.你看我在 X 轴上有刺激条件,我有集群和细胞因子分组测量。 But all the values are the sum of all IDs, they are stacked.但是所有的值都是所有 ID 的总和,它们是堆叠的。

Taking the top left corner plot as an example.以左上角 plot 为例。 Instead I want to see for Cluster 10, GMCSF, each distinct patient ID should be grouped, each give me 2 bars with UNS on the left next to a 3S on the right, then it should be next ID in the cluster, UNS 3S, then next ID in this cluster.相反,我想查看集群 10,GMCSF,每个不同的患者 ID 应该被分组,每个给我 2 个条形图,左边是 UNS,右边是 3S,然后它应该是集群中的下一个 ID,UNS 3S,然后是该集群中的下一个 ID。

I know this might look busy, but each cluster will have less than 10 differnt IDs in it, so this way I can see if each individual ID sample all have the same increase or decreas in each cluster for a given cytokine measured.我知道这可能看起来很忙,但每个集群中的不同 ID 少于 10 个,因此我可以查看每个单独的 ID 样本是否在每个集群中对于所测量的给定细胞因子都有相同的增加或减少。

assume my data假设我的数据

B2.long <- my data in long form

m <- ggplot(B2.long,aes(x=Stimulation, y=Values))+
  geom_bar(position="dodge", stat="identity")+
  facet_grid( Cluster.membership~cytokine.measured)


print(m)

在此处输入图像描述

Try x = ID and fill = Stimulation.尝试 x = ID 并填充 = 刺激。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM