【问题标题】:setting x-limits on ggcyto plot doesn't seem to do the trick在 ggcyto 图上设置 x-limits 似乎不起作用
【发布时间】:2021-06-20 19:31:24
【问题描述】:

我正在尝试在 ggcyto(ggplot2) 图上设置 x 限制,但它似乎不起作用。我设置的 x 限制一直向右挤压,并且有很多空白空间。不知道还有什么可以尝试的。我尝试设置 biexp 比例,但看起来一样。

library(ggcyto)
library(ggplot2)
library(flowCore)

fs <- read.flowSet(fcs_files, path=(dir_path))


ggcyto(fs[[2]],
              aes(x = "FSC-A", 
              y = "SSC-A")  
              ) + 
  geom_hex(bins = 26) +
  xlab("") +
  ylab("") +
  theme(
    strip.text = element_text(size = 5),
  ) +
  scale_x_continuous(breaks = c(0, 18000), labels = function(x) formatC(x, format="e", digits =1), limits=c(0, 20000))) #+
  #scale_x_flowjo_biexp(maxValue = 20000, widthBasis = -10)  

添加limits=c(0, 20000) 给我这个警告:Warning message: Removed 14 rows containing non-finite values (stat_binhex).

【问题讨论】:

    标签: r ggplot2 bioconductor


    【解决方案1】:

    没有您的数据,因此无法重现奇怪的轴。我会检查你的数据是否有负值。此外,ggcyto 包装器对您的限制有一些限制。

    使用下面的示例数据,我将第一列“FSC”上的 2 个值设置为 -999,我得到了类似的错误:

    library(ggcyto)
    data(GvHD)
    da = GvHD[[1]]
    exprs(da)[1:2,1] = -999 
        
    ggcyto(da, aes(x = `FSC-H`, y =  `SSC-H`)) +
    geom_hex(bins = 50) +
    scale_x_continuous(breaks =c(0,800),limits = c(0,2000))
    

    还有错误:

    警告消息:已删除 2 行包含非限定值 (stat_binhex)。

    如果我删除带有负值的条目并使用ggplot2 而不是ggcyto,它可以工作

    da = da[rowMeans(exprs(da[,1:2])>0) == 1,]
    
    ggplot(da,aes(x = `FSC-H`, y =  `SSC-H`)) + 
    geom_hex(bins=50) + 
    scale_x_continuous(breaks =c(0,800),limits=c(0,1200))+
    scale_fill_distiller(palette = "Spectral")
    

    在您的示例中,您可以尝试以下操作:

    da = fs[[2]]
    da = da[rowMeans(exprs(da[,c("FSC-A","SSC-A")])>0) == 1,]
    
    ggplot(da,aes(x = `FSC-A`,y = `SSC-A`)) + 
    geom_hex(bins = 26) +
    scale_x_continuous(breaks = c(0, 18000),limits=c(0, 20000))) 
    

    【讨论】:

    • 嗨@StupidWolf,感谢您的建议!有效!我还有一个问题。调色板默认为蓝色阴影。我想保留ggcyto 使用的原始调色板。我该如何设置?像这样的东西? scale_fill_gradientn(colors = ???)
    • 使用scale_fill_distiller(palette = "Spectral")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 2019-06-19
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多