I'm trying to do a meta-analysis on many genes using R package "metafor", I know how to do it one gene at a time but it would be ridiculous to do so for thousands of genes. Could somebody help me out of this! Appreciate any suggestions!
I have all the results of se and HR for all the genes named 'se_summary' and 'HR_summary' respectively.
I need to use both se and HR of these genes from five studies "ICGC, TCGA, G71, G62, G8" as input to conduct the meta analysis.
The code I used to do the meta analysis for one single gene (using gene AAK1 as an example) is:
library(metafor)
se.AAK1 <- as.numeric(se_summary[rownames(se_summary) == 'AAK1',][,-1])
HR.AAK1 <- as.numeric(HR_summary[rownames(HR_summary) == 'AAK1',][,-1])
beta.AAK1 <- log(HR.AAK1)
####First I need to use the random model to see if the test for Heterogeneity is significant or not.
pool.AAK1 <- rma(beta.AAK1, sei=se.AAK1)
summary(pool.AAK1)
#### and this gives the following output:
#>Random-Effects Model (k = 5; tau^2 estimator: REML)
#> logLik deviance AIC BIC AICc
#> -2.5686 5.1372 9.1372 7.9098 21.1372
#>tau^2 (estimated amount of total heterogeneity): 0.0870 (SE = 0.1176)
#>tau (square root of estimated tau^2 value): 0.2950
#>I^2 (total heterogeneity / total variability): 53.67%
#>H^2 (total variability / sampling variability): 2.16
#>Test for Heterogeneity:
#>Q(df = 4) = 8.5490, p-val = 0.0734
#>Model Results:
#>estimate se zval pval ci.lb ci.ub
#> -0.3206 0.1832 -1.7500 0.0801 -0.6797 0.0385 .
#>---
#>Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
####If the I^2 > 50%, we still use the Random-effect Model but if the I^2 <= 50%, we then use the Fixed-effect Model
pool.AAK1 <- rma(beta.AAK1, sei=se.AAK1, method="FE")
summary(pool.AAK1)
####this gives the following output:
#>Fixed-Effects Model (k = 5)
#> logLik deviance AIC BIC AICc
#> -2.5793 8.5490 7.1587 6.7681 8.4920
#>Test for Heterogeneity:
#>Q(df = 4) = 8.5490, p-val = 0.0734
#>Model Results:
#>estimate se zval pval ci.lb ci.ub
#> -0.2564 0.1191 -2.1524 0.0314 -0.4898 -0.0229 *
#>---
#>Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
This works just fine if I got only one gene, but I need to do it all at one time for all these genes and then export the output including "Heterogeneity p-val", and all the model results "estimate, se, zval, pval, ci.lb, ci.ub " to one .txt file, each row for a gene, the output should be like this:
Gene_symbol Heterogeneity_p-val estimate se zval pval ci.lb ci.ub
AAK1 0.0734 -0.2564 0.1191 -2.1524 0.0314 -0.4898 -0.0229
A2M 0.9664 0.1688 0.1173 1.4388 0.1502 -0.0611 0.3987
In case of need, here is a piece of sample data "se_summary"
Gene_symbol ICGC_se TCGA_se G71_se G62_se G8_se
A1CF 0.312 0.21 0.219 0.292 0.381
A2M 0.305 0.21 0.219 0.292 0.387
A2ML1 0.314 0.211 0.222 0.289 0.389
A4GALT 0.305 0.21 0.225 0.288 0.388
A4GNT 0.306 0.211 0.222 0.288 0.385
AAAS 0.308 0.213 0.223 0.298 0.38
AACS 0.307 0.209 0.221 0.287 0.38
AADAC 0.302 0.212 0.221 0.293 0.404
AADAT 0.308 0.214 0.22 0.288 0.391
AAK1 0.304 0.209 0.22 0.303 0.438
AAMP 0.303 0.211 0.222 0.288 0.394
And a piece of sample data "HR_summary"
Gene_symbol ICGC_HR TCGA_HR G71_HR G62_HR G8_HR
A1CF 1.689 1.427 0.864 1.884 1.133
A2M 1.234 1.102 1.11 1.369 1.338
A2ML1 0.563 0.747 0.535 1.002 0.752
A4GALT 0.969 0.891 0.613 0.985 0.882
A4GNT 1.486 0.764 1.051 1.317 1.465
AAAS 1.51 1.178 1.076 0.467 0.681
AACS 1.4 1.022 1.255 1.006 1.416
AADAC 0.979 0.642 1.236 1.581 1.234
AADAT 1.366 1.405 1.18 1.057 1.408
AAK1 1.04 0.923 0.881 0.469 0.329
AAMP 1.122 0.639 1.473 0.964 1.284
point 1: if your data is collected from different populations, you should not use fixed effect model. because HR could be difference among your populations.
point 2: if you convert HR to log(HR), therefore SE should be calculated for log(HR).
your data:
se_summary=data.frame(
Gene_symbol=c("A1CF","A2M","A2ML1","A4GALT","A4GNT","AAAS","AACS","AADAC","AADAT","AAK1","AAMP"),
ICGC_se=c(0.312,0.305,0.314,0.305,0.306,0.308,0.307,0.302,0.308,0.304,0.303),
TCGA_se=c(0.21,0.21,0.211,0.21,0.211,0.213,0.209,0.212,0.214,0.209,0.211),
G71_se=c(0.219,0.219,0.222,0.225,0.222,0.223,0.221,0.221,0.22,0.22,0.222),
G62_se=c(0.292,0.292,0.289,0.288,0.288,0.298,0.287,0.293,0.288,0.303,0.288),
G8_se=c(0.381,0.387,0.389,0.388,0.385,0.38,0.38,0.404,0.391,0.438,0.394))
and
HR_summary=data.frame(
Gene_symbol=c("A1CF","A2M","A2ML1","A4GALT","A4GNT","AAAS","AACS","AADAC","AADAT","AAK1","AAMP"),
ICGC_HR=c(1.689,1.234,0.563,0.969,1.486,1.51,1.4,0.979,1.366,1.04,1.122),
TCGA_HR=c(1.427,1.102,0.747,0.891,0.764,1.178,1.022,0.642,1.405,0.923,0.639),
G71_HR=c(0.864,1.11,0.535,0.613,1.051,1.076,1.255,1.236,1.18,0.881,1.473),
G62_HR=c(1.884,1.369,1.002,0.985,1.317,0.467,1.006,1.581,1.057,0.469,0.964),
G8_HR=c(1.133,1.338,0.752,0.882,1.465,0.681,1.416,1.234,1.408,0.329,1.284))
1)merge data
data=cbind(se_summary,log(HR_summary[,-1]))
2) a function to calculate meta-log HR
met=function(x) {
y=rma(as.numeric(x[7:11]), sei=as.numeric(x[2:6]))
y=c(y$b,y$beta,y$se,y$zval,y$pval,y$ci.lb,y$ci.ub,y$tau2,y$I2)
y
}
3)perform function for all rows
results=data.frame(t(apply(data,1,met)))
rownames(results)=rownames(data)
colnames(results)=c("b","beta","se","zval","pval","ci.lb","ci.ub","tau2","I2")
4)results
> results
b beta se zval pval
A1CF 0.27683114 0.27683114 0.1538070 1.7998601 0.071882735
A2M 0.16877042 0.16877042 0.1172977 1.4388214 0.150201136
A2ML1 -0.37676308 -0.37676308 0.1182825 -3.1852811 0.001446134
A4GALT -0.18975044 -0.18975044 0.1179515 -1.6087159 0.107678477
A4GNT 0.09500277 0.09500277 0.1392486 0.6822528 0.495079085
AAAS -0.07012629 -0.07012629 0.2000932 -0.3504680 0.725987468
AACS 0.15333550 0.15333550 0.1170061 1.3104915 0.190029610
AADAC 0.04902471 0.04902471 0.1738017 0.2820727 0.777887764
AADAT 0.23785528 0.23785528 0.1181503 2.0131593 0.044097875
AAK1 -0.32062727 -0.32062727 0.1832183 -1.7499744 0.080122725
AAMP 0.02722082 0.02722082 0.1724461 0.1578512 0.874574077
ci.lb ci.ub tau2 I2
A1CF -0.024625107 0.57828740 0.04413257 37.89339
A2M -0.061128821 0.39866965 0.00000000 0.00000
A2ML1 -0.608592552 -0.14493360 0.00000000 0.00000
A4GALT -0.420931120 0.04143024 0.00000000 0.00000
A4GNT -0.177919527 0.36792508 0.02455208 25.35146
AAAS -0.462301836 0.32204926 0.12145183 62.23915
AACS -0.075992239 0.38266324 0.00000000 0.00000
AADAC -0.291620349 0.38966978 0.07385974 50.18761
AADAT 0.006285038 0.46942552 0.00000000 0.00000
AAK1 -0.679728455 0.03847392 0.08700387 53.66905
AAMP -0.310767314 0.36520895 0.07266674 50.07330
Put the data in long format, with both the effect sizes and the se data side by side, then use a split and apply rma to each of these. You can make your own version of broom's tidy function just for rma objects.
library(metafor)
library(reshape)
se_summary<-read.table(text="
Gene_symbol ICGC_se TCGA_se G71_se G62_se G8_se
AADAT 0.308 0.214 0.22 0.288 0.391
AAK1 0.304 0.209 0.22 0.303 0.438
AAMP 0.303 0.211 0.222 0.288 0.394
",header=T)
HR_summary<-read.table(text="
Gene_symbol ICGC_HR TCGA_HR G71_HR G62_HR G8_HR
AADAT 0.308 0.214 0.22 0.288 0.391
AAK1 0.304 0.209 0.22 0.303 0.438
AAMP 0.303 0.211 0.222 0.288 0.394
",header=T)
HR_summary<-melt(HR_summary,id.vars = "Gene_symbol")%>%
mutate(.,variable=sapply(strsplit(as.character(variable), split='_', fixed=TRUE), function(x) (x[1])))%>%
rename(gene=variable)
se_summary<-melt(se_summary,id.vars = "Gene_symbol")%>%
mutate(.,variable=sapply(strsplit(as.character(variable), split='_', fixed=TRUE), function(x) (x[1])))%>%
rename(gene=variable)
HR_summary<-merge(HR_summary,se_summary,by=c("Gene_symbol","gene"),suffixes=c(".HR",".se"))
tidy.rma<-function(x) {
return(data.frame(estimate=x$b,se=x$se,zval=x$zval,ci.lb=x$ci.lb,ci.ub=x$ci.ub,k=x$k,Heterog_pv=x$QEp#the main stuff: overall ES, etc
#variance components( random effects stuff): nlvls is n sites
)) #test for heterogeneity q value and p-value
}
rbindlist(lapply(split(HR_summary, droplevels(HR_summary$Gene_symbol)),
function(x)with(x, tidy.rma(rma(yi=value.HR, sei=value.se,method="FE")))),idcol = "Gene_symbol2")
I am trying to output the misclassification of my neural network using 10 different seeds, after each iteration inside the loop I am trying to output the value of misrate.test which is the misclassification. Here is preview of the data + code snippet,I called the data new.train I can't the that value after running my program
V1 V70 V30 V86 V22 V107 V46 V78 V94 V62 V91
V76
4 7 1.000 -0.421 0.931 -0.114 -0.186 1.000 0.695 -0.363 1.000
-0.949 -0.606
11 7 1.000 1.000 1.000 -0.973 -1.000 0.167 -0.121 0.265 -0.415
-1.000 -1.000
15 7 -0.870 -1.000 -0.289 -1.000 -0.279 -1.000 -1.000 -1.000 -1.000
-0.715 0.918
16 7 0.758 -1.000 -0.535 0.901 0.508 -0.786 -0.913 -1.000 -0.796
-0.293 0.913
23 7 0.047 0.531 -0.983 0.212 -0.965 1.000 0.343 -0.427 0.993
-1.000 -0.857
26 7 -0.158 0.912 -1.000 -0.173 0.469 -0.117 -1.000 -1.000 -0.977
-0.020 0.974
library(nnet)
diff.seed <- c(1,66,70,222,1345,766,453,2999,7654,10000)
for(i in diff.seed){
set.seed(i) #Set different seed
digit.nnet <- nnet(V1~., data=new.train, size = 5, rang=0.1, decay=5e-4,
maxit=1000) #Train the network on new.train
y.hat <- as.numeric(predict(digit.nnet,new.test, type = "class")) #Apply on
new.test which is same as new.train
misrate.test <- sum(y.hat !=
new.test[,1])/length(new.test[,1])#Misclassification rate
misrate.test #Attempt to output it
}
I cannot reproduce your question exactly (do not have new.test), but one of these should work:
library(nnet)
diff.seed <- c(1,66,70,222,1345,766,453,2999,7654,10000)
for(i in diff.seed) {
set.seed(i) #Set different seed
digit.nnet <- nnet(V1~., data=new.train, size = 5, rang=0.1, decay=5e-4, maxit=1000) #Train the network on new.train
y.hat <- as.numeric(predict(digit.nnet,new.test, type = "class")) #Apply on new.test which is same as new.train
misrate.test <- sum(y.hat != new.test[,1])/length(new.test[,1])#Misclassification rate
print(misrate.test) #Attempt to output it
}
or
misrates <- sapply(diff.seed, function(i) {
set.seed(i) #Set different seed
digit.nnet <- nnet(V1~., data=new.train, size = 5, rang=0.1, decay=5e-4, maxit=1000) #Train the network on new.train
y.hat <- as.numeric(predict(digit.nnet,new.test, type = "class")) #Apply on new.test which is same as new.train
misrate.test <- sum(y.hat != new.test[,1])/length(new.test[,1])#Misclassification rate
misrate.test
})
I have a discharge data that i want to display; observed vs simulated. The data is as follows;
Time observed simulated
Jan-86 0.105 0.1597
Feb-86 0.0933 0.1259
Mar-86 3.5336 0.41
Apr-86 8.8999 2.494
May-86 5.2431 1.767
Jun-86 0.9747 1.96
Jul-86 0.079 1.98
Aug-86 0.0154 1.729
Sep-86 0.0053 1.419
Oct-86 0.0135 1.121
Nov-86 0.0235 0.8664
Dec-86 0.017 0.658
Jan-87 0.017 0.4925
Feb-87 0.017 0.3855
Mar-87 3.3483 1.089
Apr-87 3.3156 1.704
May-87 0.5563 1.327
Jun-87 0.2565 1.166
Jul-87 0.0446 1.012
Aug-87 0.0096 0.8278
Sep-87 0.0007 0.6567
Oct-87 0.0018 0.5083
Nov-87 0.0139 0.3892
Dec-87 0.0087 0.2953
Jan-88 0.0025 0.2196
Feb-88 0.0017 0.1641
Mar-88 0.0099 0.3858
Apr-88 1.6217 3.929
May-88 0.3398 0.5156
Jun-88 0.762 0.5537
Jul-88 0.0242 0.4985
Aug-88 0.0002 0.4125
Sep-88 0.0003 0.4027
Oct-88 0 0.2918
Nov-88 0 0.2388
Dec-88 0.0005 0.2024
Jan-89 0.0003 0.147
Feb-89 0.0004 0.1157
Mar-89 0.0006 0.3886
Apr-89 6.5433 10.92
May-89 0.8047 1.685
Jun-89 0.7968 1.486
Jul-89 0.0836 1.407
Aug-89 0.0024 1.22
Sep-89 0.0001 0.9965
Oct-89 0 0.7846
Nov-89 0.0005 0.6097
Dec-89 0 0.4636
Jan-90 0 0.3469
Feb-90 0 0.271
Mar-90 0.2724 0.9063
Apr-90 0.3768 2.902
May-90 0.0776 0.5038
Jun-90 0.1327 0.5622
Jul-90 0.0636 0.5068
Aug-90 0.0005 0.4169
Sep-90 0 0.3328
Oct-90 0 0.2611
Nov-90 0 0.2016
Dec-90 0 0.1549
Jan-91 0 0.116
Feb-91 0.0004 0.0904
Mar-91 0.0024 0.0709
Apr-91 0.0056 0.3813
May-91 0.1312 0.6567
Jun-91 0.1033 0.6053
Jul-91 1.1491 0.6226
Aug-91 0.0957 0.5423
Sep-91 0.01 0.4529
Oct-91 0.009 0.374
Nov-91 0.0436 0.3132
Dec-91 0.0629 0.2344
Jan-92 0.0238 0.1775
Feb-92 0.0125 0.1378
Mar-92 2.4242 3.399
Apr-92 2.9119 4.284
May-92 1.0843 1.854
Jun-92 0.1473 1.7
Jul-92 0.3467 1.451
Aug-92 0.0143 1.182
Sep-92 0.0193 2.272
Oct-92 0.035 1.332
Nov-92 0.0132 1.181
Dec-92 0.0353 0.9716
Jan-93 0.0213 0.7097
Feb-93 0.0196 0.5596
Mar-93 0.2553 5.669
Apr-93 3.4093 4.912
May-93 0.4553 1.575
Jun-93 1.4621 1.56
Jul-93 2.7732 2.622
Aug-93 7.4911 1.587
Sep-93 7.7134 1.381
Oct-93 0.4065 1.133
Nov-93 0.3042 0.9257
Dec-93 0.1669 0.7514
Jan-94 0.0756 0.5657
Feb-94 0.0317 0.4464
Mar-94 1.3576 3.802
Apr-94 1.5093 4.446
May-94 0.8696 1.246
Jun-94 0.3097 1.426
Jul-94 4.1223 1.66
Aug-94 0.6915 0.7939
Sep-94 3.9228 0.6434
Oct-94 1.5528 0.5081
Nov-94 3.0506 0.3907
Dec-94 0.6294 0.3053
Jan-95 0.2484 0.2327
Feb-95 0.1053 0.1842
Mar-95 9.4852 7.073
Apr-95 3.8737 3.122
May-95 3.0692 1.754
Jun-95 0.3433 1.386
Jul-95 2.6554 1.297
Aug-95 0.3252 0.9797
Sep-95 0.2854 0.7803
Oct-95 0.2667 0.6097
Nov-95 0.1444 0.4692
Dec-95 0.1098 0.355
Jan-96 0.0696 0.265
Feb-96 0.0399 0.4352
Mar-96 0.0419 0.2793
Apr-96 16.2771 17.33
May-96 25.3653 21.04
Jun-96 0.4064 4.901
Jul-96 0.3028 3.886
Aug-96 0.097 3.1
Sep-96 0.0325 2.51
Oct-96 0.0949 2.009
Nov-96 0.2763 1.614
Dec-96 0.1307 1.252
Jan-97 0.0778 0.9253
Feb-97 0.0661 0.7211
Mar-97 0.0703 0.7519
Apr-97 27.3434 21.65
May-97 4.2895 7.989
Jun-97 0.4939 3.661
Jul-97 6.7193 3.92
Aug-97 0.1174 2.802
Sep-97 0.0858 2.229
Oct-97 2.0501 1.789
Nov-97 0.891 1.644
Dec-97 0.3561 1.288
Jan-98 0.133 0.94
Feb-98 0.8482 2.56
Mar-98 7.2317 6.613
Apr-98 3.7604 4.181
May-98 3.039 2.323
Jun-98 5.3291 2.492
Jul-98 5.6387 2.607
Aug-98 0.1308 1.943
Sep-98 0.0937 1.647
Oct-98 1.4565 1.641
Nov-98 0.7778 1.563
Dec-98 0.5755 1.692
Jan-99 0.0573 1.65
Feb-99 0.0783 1.489
Mar-99 2.3554 7.688
Apr-99 25.3018 18.41
May-99 8.7571 5.154
Jun-99 14.8313 3.564
Jul-99 4.7535 2.423
Aug-99 3.6622 1.898
Sep-99 5.0639 1.524
Oct-99 0.9153 1.186
Nov-99 0.4436 0.905
Dec-99 0.181 0.6864
Jan-00 0.1015 0.5129
Feb-00 1.9763 0.3953
Mar-00 2.5832 0.3083
Apr-00 3.6585 0.2388
May-00 0.9701 0.182
Jun-00 7.1744 0.1605
Jul-00 1.7145 0.1494
Aug-00 0.6677 0.1364
Sep-00 0.1858 0.1195
Oct-00 1.1442 0.0997
Nov-00 15.1503 0.6839
Dec-00 0.5526 0.4275
01-Jan 0.182 0.6061
01-Feb 0.1582 0.5254
01-Mar 0.7527 0.437
01-Apr 18.8305 21
01-May 4.0794 2.765
01-Jun 1.7906 5.399
01-Jul 0.2344 2.615
01-Aug 2.8721 1.896
01-Sep 0.108 1.555
01-Oct 0.0896 1.237
01-Nov 0.6865 0.9588
01-Dec 0.1609 0.7329
02-Jan 0.0987 0.5496
02-Feb 0.081 0.4299
02-Mar 0.0671 0.4125
02-Apr 1.9161 5.189
02-May 2.8088 2.423
02-Jun 18.2132 2.137
02-Jul 2.881 2.783
02-Aug 0.676 1.102
02-Sep 1.309 0.892
02-Oct 0.1844 0.7183
02-Nov 0.1415 0.56
02-Dec 0.0781 0.4277
03-Jan 0.0897 0.3211
03-Feb 0.0191 0.2515
03-Mar 1.1978 2.32
03-Apr 1.4536 2.175
03-May 1.2194 0.9472
03-Jun 2.2049 0.7456
03-Jul 0.1934 0.6395
03-Aug 0.0362 0.5237
03-Sep 0.0047 0.4738
03-Oct 0.0338 0.3477
03-Nov 0.1166 0.2821
03-Dec 0.0301 0.2319
04-Jan 0.0151 0.1851
04-Feb 0.0218 0.1462
04-Mar 2.9284 3.967
04-Apr 5.113 8.21
04-May 14.4488 6.077
04-Jun 8.7876 4.92
04-Jul 0.7572 2.781
04-Aug 0.3186 2.023
04-Sep 1.7134 1.648
04-Oct 0.834 1.385
04-Nov 1.5215 1.571
04-Dec 0.1535 1.175
05-Jan 0.0515 0.8762
05-Feb 0.0535 0.7016
05-Mar 0.5916 2.954
05-Apr 10.2761 12.22
05-May 4.3927 3.95
05-Jun 12.6566 8.826
05-Jul 13.6267 4.855
05-Aug 11.4682 3.241
05-Sep 1.2082 2.454
05-Oct 1.1875 1.986
05-Nov 1.5555 1.566
05-Dec 0.3229 1.294
06-Jan 0.1832 1.055
06-Feb 0.112 0.885
06-Mar 0.3341 3.006
06-Apr 24.8525 19.75
06-May 6.2187 4.442
06-Jun 0.3634 2.697
06-Jul 0.0534 1.889
06-Aug 0.0439 1.571
06-Sep 0.02 1.261
06-Oct 0.0418 0.9836
06-Nov 0.0612 0.7535
06-Dec 0.0747 0.5717
07-Jan 0.0644 0.43
07-Feb 0.0339 0.3319
07-Mar 2.8046 2.675
07-Apr 2.7156 3.412
07-May 0.5788 2.576
07-Jun 8.5705 9.888
07-Jul 1.3929 2.897
07-Aug 0.1146 1.758
07-Sep 0.0374 1.486
07-Oct 0.1637 1.338
07-Nov 0.1599 1.2
07-Dec 0.1165 0.9649
08-Jan 0.054 0.7372
08-Feb 0.024 0.5469
08-Mar 0.04 0.6989
08-Apr 2.3773 9.219
08-May 1.3455 3.223
08-Jun 1.4375 4.011
08-Jul 0.531 2.341
08-Aug 0.0512 1.618
08-Sep 0.0902 1.377
08-Oct 2.8219 1.115
08-Nov 4.7166 0.9028
08-Dec 0.3393 0.8564
09-Jan 0.1303 0.6376
09-Feb 0.1594 0.7089
09-Mar 10.3111 5.402
09-Apr 14.466 14.64
09-May 6.0214 13.73
09-Jun 5.4491 6.086
09-Jul 7.4774 4.059
09-Aug 0.4845 2.885
09-Sep 0.1321 2.208
09-Oct 0.0935 1.755
09-Nov 0.1702 1.367
09-Dec 0.0786 1.183
10-Jan 0.049 1.461
10-Feb 0.0502 0.8349
10-Mar 9.9809 7.328
10-Apr 2.1785 5.341
10-May 5.54 9.544
10-Jun 6.5798 10.35
10-Jul 1.4304 5.972
10-Aug 0.3424 3.768
10-Sep 8.7223 3.844
10-Oct 5.7656 4.88
10-Nov 3.7897 4.978
10-Dec 0.5271 3.289
I tried the following codes to display the data
require(xts)
data <- read.csv('./flowout13.csv')
dd1<-data.frame(data[2:3])
dd1<-ts(dd1,frequency = 12,start = 1986)
plot(as.xts(dd1),major.format="%y-%m")
title(main="Calibrated observed and simulated discharge",xlab="Time",ylab="discharge in mm")
legend("topleft", inset=0.10, title="Discharge",
c("observed","simulated","r2=0.8", "NSE=0.60"), fill=terrain.colors(2), horiz=FALSE)
And the graph does not show the actual color of the graphs.I want the black lines as observed and red as simulated but it shows different.i do not want the r2 and NSE be in any color they are just the values, i added from different calculations. I also want to change the position of xlab below the dates. Please help out. I am working on r studio.
Is this what you're looking for?
plot(as.xts(dd1), major.format="%y-%m", col = terrain.colors(2))
I'm trying to declare the colorAxis and let a series of computed "Scores" define the gradient for coloring the bubbles. The visualization just keeps giving me random colors, all with the "OutlierScore" next to them on an ugly legend to the right of the plot. I don't understand what I'm doing wrong as my options list matches all of the demo codes I find. I'm using the final gvisBubbleChart statement as the output to my renderGvis code in server.R.
Here's some sample data:
Attribute CloseRate Quotes OutlierScore Size
AdvancedShopper:N 0.261 3411 292.47 1.016
AdvancedShopper:Y 0.119 10421 259.68 2.283
PriorCarrier:HP 0.277 1876 186.46 0.739
Vehicles:1 0.183 8784 179.98 1.988
Vehicles:2 0.106 3471 121.81 1.027
LeadType:Cold 0.104 3177 117.09 0.974
SPINOFF:Y 0.414 510 115.65 0.492
LeadType:Warm 0.223 2184 115.47 0.795
MULTI_CAR_DSCNT_FLG:HMC 0.303 879 107.88 0.559
MULTI_CAR_DSCNT_FLG:MC 0.111 3451 105.75 1.024
PRI_CARR_NME:HP 0.253 1287 100.58 0.633
PriorCarrier:GEICO 0.099 2476 99.74 0.847
PriorCarrier:No Prior Insurance 0.304 802 99.61 0.545
PRI_CARR_NME:No Prior Insurance 0.304 802 99.61 0.545
FR_BAND:P-R 0.112 3227 98.15 0.983
PIP_DED:2,500 0.197 3053 95.11 0.952
AgencyName:South Agency 0.213 2120 94.81 0.783
RSrc:SPIN-OFF Additional Policy 0.434 373 91.99 0.467
CompanionType:None 0.141 11332 87.60 2.448
D2V:D1V1 0.175 5830 85.67 1.454
Here's my gvisBubbleChart declaration.
YLim = c(0,max(GData$Quotes)*1.05)
XLim = c(0,max(GData$CloseRate)*1.01)
gvisBubbleChart(GData, idvar="Attribute", xvar="CloseRate", yvar="Quotes", colorvar="OutlierScore", sizevar="Size",
options=list(title="One-Way Bubble Chart",
hAxis=paste("{title: 'Close Rate', minValue:0, maxValue:",XLim[2],"}",sep=""),
vAxis=paste("{title: 'Quotes', minValue:0, maxValue:",YLim[2],"}",sep=""),
width=1400, height=600, colorAxis="{minValue: 0, colors: ['red', 'green']}",
sizeAxis = '{minValue: 0, maxSize: 10}',
bubble="{textStyle:{color: 'none'}}"))