2016-09-09 18 views
-1

私はプロットする必要があるデータの大部分をプロットするために以下の関数を使用します。私はオンラインで見つけたコードの異なる塊のおかげでそれを作成しました。これまで私はこれまで何の問題も経験していません。 ここにプロット関数があります。プロット関数はデータがベクトル型でなければなりませんでした。 'NULL'でした

library(ggplot2) 
library(reshape2) 

#' Plot a given mean with error bars 
#' @param resultTable The table with all the result to plot 
#' @param techniques The name of the techniques in the form of a list/vector 
#' @param nbTechs The number of given techniques 
#' @param ymin The minimum value for y 
#' @param ymax The maximum value for y 
#' @param xAxisLabel The label for the x (vertical) axis 
#' @param yAxisLable The label for the y (horizontal) axis 
#' @return 
#' 
barChartTime <- function(resultTable, techniques, nbTechs = -1, ymin, ymax, xAxisLabel = "I am the X axis", yAxisLabel = "I am the Y Label"){ 
    #tr <- t(resultTable) 
    if(nbTechs <= 0){ 
    stop('Please give a positive number of Techniques, nbTechs'); 
    } 

    tr <- as.data.frame(resultTable) 
    nbTechs <- nbTechs - 1 ; # seq will generate nb+1 

    #now need to calculate one number for the width of the interval 
    tr$CI2 <- tr$upperBound_CI - tr$mean_time 
    tr$CI1 <- tr$mean_time - tr$lowerBound_CI 

    #add a technique column 
    tr$technique <- factor(seq.int(0, nbTechs, 1)); 

    breaks <- c(as.character(tr$technique)); 
    print(tr) 
    g <- ggplot(tr, aes(x=technique, y=mean_time)) + 
    geom_bar(stat="identity",fill = I("#CCCCCC")) + 
    geom_errorbar(aes(ymin=mean_time-CI1, ymax=mean_time+CI2), 
        width=0,     # Width of the error bars 
        size = 1.1 
    ) + 
    #labs(title="Overall time per technique") + 
    labs(x = xAxisLabel, y = yAxisLabel) + 
    scale_y_continuous(limits = c(ymin,ymax)) + 
    scale_x_discrete(name="",breaks,techniques)+ 
    coord_flip() + 
    theme(panel.background = element_rect(fill = 'white', colour = 'white'),axis.title=element_text(size = rel(1.2), colour = "black"),axis.text=element_text(size = rel(1.2), colour = "black"),panel.grid.major = element_line(colour = "#DDDDDD"),panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank())+ 
    geom_point(size=4, colour="black")   # dots 

    print(g) 
} 

は今、ここに(データの簡易版)は、私が使用しています(そしてそれがエラーを再現)データである:

EucliP,AngularP,EucliR,AngularR,EucliSp,AngularSp,EucliSl,AngularSl 
31.6536,30.9863,64.394,92.7838,223.478,117.555,44.7374,25.4852 
12.3592,40.7639,70.2508,176.55,10.3927,145.909,143.025,126.667 
14.572,8.98445,113.599,150.551,47.1545,54.3019,10.7038,47.7004 
41.7957,20.9542,55.1732,67.1647,52.364,41.3655,62.7036,75.65 
135.868,83.7135,14.0262,69.7183,44.987,35.9599,19.5183,66.0365 
33.5359,17.2129,6.95909,47.518,224.561,91.4999,67.1279,31.4079 
25.7285,33.6705,17.4725,58.45,43.1709,113.847,28.9496,20.0574 
48.4742,127.588,75.0804,89.1176,31.4494,27.9548,38.4563,126.248 
31.9831,80.0161,19.9592,145.891,55.2789,142.738,94.5126,136.099 
17.4044,52.3866,49.9976,150.891,104.936,77.2849,232.23,35.6963 
153.359,151.897,41.8876,46.3893,79.5218,75.2011,68.9786,91.8972 

そして、ここでは、私が使用していたコードです

data = read.table("*Path_to_file*.csv", header=T, sep=",") 
data$EucliPLog = (data$EucliP) #Before here I used to use a log transform that I tried to remove for some testing 
data$EucliRLog = (data$EucliR) #Same thing 
data$EucliSpLog = (data$EucliSp) #Same thing 
data$EucliSlLog = (data$EucliSl) #Same thing 
a1 = t.test(data$EucliPLog)$conf.int[1] 
a2 = t.test(data$EucliPLog)$conf.int[2] 
b1 = t.test(data$EucliRLog)$conf.int[1] 
b2 = t.test(data$EucliRLog)$conf.int[2] 
c1 = t.test(data$EucliSpLog)$conf.int[1] 
c2 = t.test(data$EucliSpLog)$conf.int[2] 
d1 = t.test(data$EucliSlLog)$conf.int[1] 
d2 = t.test(data$EucliSlLog)$conf.int[2] 
analysisData = c() 
analysisData$ratio = c("Sl","Sp","R","P") 
analysisData$pointEstimate = c(exp(mean(data$EucliSlLog)),exp(mean(data$EucliSpLog)),exp(mean(data$EucliRLog)),exp(mean(data$EucliPLog))) 
analysisData$ci.max = c(exp(d2), exp(c2),exp(b2), exp(a2)) 
analysisData$ci.min = c(exp(d1), exp(c1),exp(b1), exp(a1)) 

datatoprint <- data.frame(factor(analysisData$ratio),analysisData$pointEstimate, analysisData$ci.max, analysisData$ci.min) 
colnames(datatoprint) <- c("technique", "mean_time", "lowerBound_CI", "upperBound_CI ") 
barChartTime(datatoprint,analysisData$ratio ,nbTechs = 4, ymin = 0, ymax = 90, "", "Title") 

だから最後のコードのコメントで述べたlog()を使用すると、すべて正常に動作し、プロットが表示されます。しかし、私は、ログを削除しようとした私は、私が試してみました有名な

Error in matrix(value, n, p) : 
    'data' must be of a vector type, was 'NULL' 

は私のデータにNULL値を探してもらうが、どれも存在しないと私は、次の見てどこか分かりません。それを助けてくれるのが大好きです。事前に おかげ


編集:

structure(list(technique = structure(c(3L, 4L, 2L, 1L), .Label = c("P", 
"R", "Sl", "Sp"), class = "factor"), mean_time = c(1.04016257618464e+32, 
1.64430609815788e+36, 7.5457775364611e+20, 3.85267453902928e+21 
), lowerBound_CI = c(6.64977706609883e+50, 5.00358136618364e+57, 
2.03872433045407e+30, 4.93863589006376e+35), `upperBound_CI ` = c(16270292584857.9, 
540361462434140, 279286207454.44, 30055062.6409769)), .Names = c("technique", 
"mean_time", "lowerBound_CI", "upperBound_CI "), row.names = c(NA, 
-4L), class = "data.frame") 

そしてdputanalysisData上:

structure(list(ratio = c("Sl", "Sp", "R", "P"), pointEstimate = c(1.04016257618464e+32, 
1.64430609815788e+36, 7.5457775364611e+20, 3.85267453902928e+21 
), ci.max = c(6.64977706609883e+50, 5.00358136618364e+57, 2.03872433045407e+30, 
4.93863589006376e+35), ci.min = c(16270292584857.9, 540361462434140, 
279286207454.44, 30055062.6409769)), .Names = c("ratio", "pointEstimate", 
"ci.max", "ci.min")) 
+0

[OK]をクリックすると、空のプロットが表示され、欠落値に関する警告が表示されますが、エラーは表示されません。 – Axeman

+0

私はちょうどあなたがここにあるのとまったく同じコードでもう一度試してみましたが、私はまだこのエラーを受けています – LBes

+1

おそらくあなたは、エラーを生成する最小限のコードを減らそうとする可能性があります。 – Bernhard

答えて

2

ログがなければ、私は持っていません。ここdputdatatoprint上の結果は、値が10^40 ++を超えているため表示されているものですが、ログでは上限(90)を下回っています。
私はあなたがエラーを得ることはありません。

+0

それは確かに私の間違いでした。アンチ・ロギングを削除するのを忘れました。愚かな間違いでごめんなさい、それを見つけてくれてありがとう。 – LBes

関連する問題