【问题标题】:Sunflower plot with missing data缺失数据的向日葵图
【发布时间】:2013-12-08 18:16:59
【问题描述】:

看来 sunflowerplot 不适用于缺失数据。

我正在尝试编写一个清除向日葵图函数,该函数清除输入向量中的缺失值,并告知向日葵图图例中每个变量的缺失值数量。代码如下:

      library(gplots)
    CleanedSunflowerPlot <- function(x,y,...){
        m<-sum(is.na(x)) 
        n <- sum(is.na(y)) 
            x <- na.omit(x)
            y <- na.omit(y)
        sunflowerplot(x,y,...)
        smartlegend(x="left", y="top",
        c( paste(m , " missing x values") , paste(n, " missing y values"))) 

    }

我得到的错误是“xy.coords(x, y, xlabel, ylabel, log) 中的错误: 'x' 和 'y' 长度不同"

我尝试了很多不同的方法,但无法解决。谢谢。

【问题讨论】:

  • cbind x 和 y 然后删除所有缺少数据的行

标签: r


【解决方案1】:

基于@rawr 的建议:

x <- c(1,2,NA,4); y <- c(NA, 5, 3, 2)
xy <- cbind(x, y)
xy
#       x  y
# [1,]  1 NA
# [2,]  2  5
# [3,] NA  3
# [4,]  4  2

xy[ !is.na(x) & !is.na(y), ]
#      x y
# [1,] 2 5
# [2,] 4 2

sunflowerplot(xy[, 1], xy[, 2])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 2017-01-31
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 2021-12-01
    相关资源
    最近更新 更多