【问题标题】:How to plot half circles within a matrix in R?如何在R中的矩阵内绘制半圆?
【发布时间】:2021-07-09 05:46:22
【问题描述】:

我正在使用 R 绘制一个上调/下调的基因计数矩阵,其中 y 轴是类别,x 轴是每个处理中的计数。这是我用 corrplot 绘制的矩阵结构的示例:

corrplot 的矩阵图

我希望每个单元格都有一个分割圆图,而不是像上图那样在每个单元格中绘制完整的圆圈。一半包含类型“up”值,另一半包含“down”值。

使用这个帖子作为example 的圆形图,我已经能够绘制圆圈,但我正在努力将它变成一个类似矩阵的图形。以下是一些示例数据:

df <- data.frame(category = rep(c("A", "B"), each = 2),
             type = rep(c("up", "down"), 4),
             treatment = rep(c("treat1", "treat2", "treat3", "treat4"), each = 4),
             count = c(19419, 1132, 8138, 947, 8349, 436, 789, 1580))

df$treatment <- as.factor(df$treatment)

library(ggplot2)
ggplot(df, aes(x=category, y=sqrt(count), fill=type)) + geom_col(width =1) +
  coord_polar(theta = "x", direction = -1) +
  facet_wrap(category~treatment) +
  theme_void()

如何将这些圆圈排列成类似矩阵的图形?如何在矩阵的每个单元格内绘制分割圆?

任何建议将不胜感激。非常感谢!!

【问题讨论】:

    标签: r ggplot2 matrix r-corrplot ggcorrplot


    【解决方案1】:
    ggplot(df, aes(x=category, y=sqrt(count), fill=type)) + geom_col(width =999, position="dodge") +
      coord_polar(theta = "x", direction = -1, start=pi/2) +
      facet_grid(category~treatment) +
      theme_void()
    

    旋转绘图并让上下部分在不同方向上绘制

    【讨论】:

      猜你喜欢
      • 2015-10-10
      • 1970-01-01
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 2021-11-21
      • 2018-12-05
      相关资源
      最近更新 更多