Error: Attempted to create layer with no stat (ggcorplot)

2,580 views
Skip to first unread message

Ilya Schurov

unread,
Apr 23, 2016, 1:55:15 PM4/23/16
to Deducer
I'm trying to reproduce the code snippet from ggcorplot help page and get the following error:

> data(mtcars)
> corr.mat1<-cor.matrix(variables=d(mpg,carb,carb+rnorm(length(carb))),,
+ data=mtcars,
+ test=cor.test,
+ method='spearman',
+ alternative="two.sided",exact=FALSE)
>
> p<-ggcorplot(corr.mat1,data = mtcars)
Error: Attempted to create layer with no stat.

Are there any ways to solve it?

--
Sincerely yours,
Ilya V. Schurov.

Ian Fellows

unread,
Apr 29, 2016, 1:01:00 PM4/29/16
to ded...@googlegroups.com
This is a known issue caused during an update to ggplot2. The fix is not yet on CRAN, but it is fixed in the github repo


best,
Ian

--

---
You received this message because you are subscribed to the Google Groups "Deducer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deducer+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

zhan...@gmail.com

unread,
Nov 9, 2017, 12:50:46 PM11/9/17
to Deducer
I found the following error after I coped the new version of ggcorplot from Deducer:
Error in d(eval(parse(text = nm[i]), data, parent.frame())) : 
  could not find function "d"

It looks like that there should be a function named "d". But I can't find it. any idea? thanks you for your help!

Zhanyou

Ian Fellows

unread,
Nov 9, 2017, 4:35:56 PM11/9/17
to ded...@googlegroups.com
‘d’ is another function in the Deducer package. Functions within packages often have dependancies with other functions in the package.


ian

Bruce Miller

unread,
Apr 17, 2018, 6:38:34 AM4/17/18
to ded...@googlegroups.com
Hi all,

I would like to set up an iterative read & write sequence to avoid reading and writing each file one at a time.
Hundreds of data sets to re-calculate.  The code I have works well individually, but would like to set up an iterative read, calculate and write changing the input and output file names each iteration.

I  think I have read that there is an R  feature using "Pipes" and % that may help but have not figured out how to do this.
What I am seeking is a way to read a list of TXT files, calculate the values and write the results in an iterative manner to avoid using the Data Viewer read each time.

Suggestions?

Tnx,
Bruce

# This works

>Corbre_2 <- read.table("E:/Acoustic Parameters/~Emballonuridae/Data by genus/~Corbre/Corbre_2.txt",header=T,sep="\t",quote="")

Corbre_2 [c("TBC")] <- recode.variables(Corbre_2[c("TBC")] , "0 -> NA;")

# Create new BW variable then change data file name

BW<-within(Corbre_2,BW<-Fmax-Fmin)

# Create 2 new variables for fundamental H1 and third harmonic H3 #based on Fc that is generally loudest at the 2nd harmonic.

BW<-within(BW,FcH1<-Fc*.5)

BW<-within(BW,FcH3<-FcH1*3)

BatStats<-BW

#added the H1 and H3 in the output section

BatStats<-Deducer::descriptive.table (vars = d (Dur,TBC,Fmin,Fmax,BW,Fmean,Fk,FcH1,Fc,FcH3,Sc,Pmc),data= BatStats,func.names =c("Valid N","Minimum","Maximum","Mean","St. Deviation"),func.additional= list(p10=function(x) quantile(x, c(0.10), na.rm=TRUE),p25=function(x) quantile(x, c(0.25), na.rm=TRUE),p75=function(x) quantile(x, c(0.75),na.rm=TRUE),p90=function(x) quantile(x, c(0.90),na.rm=TRUE)))

## Write the results Change output name and directory for stats.

write.csv(BatStats,file="C:\\=Bat data working\\Acoustic Parameters\\Corbre_Stats.csv")

Bruce Miller

unread,
Apr 18, 2018, 8:28:55 AM4/18/18
to ded...@googlegroups.com
Hi all,

I have searched the WWW and read many posts on Stack Overflow etc on
running multiple iterations on many data files but have not found an
answer that is useful for me to create what I need.  I am not an R power
user.

I have hundreds of simple *CSV files that I would like to process in an
iterative manner.

Ideally, I would first like to add the data file names to each data file
so on completion of the summary calculation each set of results are
unique. Each data file has the same CSV information.

An abbreviated example of the data directory would be:
Balio.txt
Balpli.txt
Cencen.txt
Cenmax.txt
Corbre.txt
Cytale.txt
Dicalb.txt
Dicing.txt
Perkap.txt
Permac.txt
Pertri.txt
Rhynas.txt
Sacbil.txt
Saccan.txt
Sacgym.txt
Saclep.tx


This is the code that works in Deducer for each individual file.  I have
used DataFile as a surrogate for each file name seen above:

    DataFile[c("TBC")] <- recode.variables(DataFile[c("TBC")] , "0 ->
            NA;")
    # Create new BW variable then change data file name
            BW<-within(DataFile,BW<-Fmax-Fmin)

    # Create 2 new variables for fundamental H1 and third harmonic H3
    #based on Fc that is generally loudest at the 2nd harmonic.
            BW<-within(BW,FcH1<-Fc*.5)
            BW<-within(BW,FcH3<-FcH1*3)
            BatStats<-BW

    #add the H1 and H3 in the output section
            BatStats<-Deducer::descriptive.table (vars = d
(Dur,TBC,Fmin,Fmax,BW,Fmean,Fk,FcH1,Fc,FcH3,Sc,Pmc),data=
            BatStats,func.names =c("Valid
N","Minimum","Maximum","Mean","St.
            Deviation"),func.additional= list(p10=function(x) quantile(x,
            c(0.10), na.rm=TRUE),p25=function(x) quantile(x, c(0.25),
            na.rm=TRUE),p75=function(x) quantile(x,
            c(0.75),na.rm=TRUE),p90=function(x) quantile(x,
            (0.90),na.rm=TRUE)))

    ## Write the results Change output name and directory for stats.
              write.csv(BatStats,file="C:\\=Bat data working\\Acoustic
              Parameters\\DataFile_Stats.csv")

What I need to do is determine how to complete iterations of the same
code for a list of files.

Any suggestions/help appreciated.
Bat Dude

Ian Fellows

unread,
Apr 18, 2018, 11:15:12 AM4/18/18
to ded...@googlegroups.com
This is not really a Deducer related question. I suggest asking on SO or r-help as a more appropriate venue. As a hint, use list.files to get all the files in a directory and use a for loop to iterate over them.

Best,
Ian

Tom Hopper

unread,
Apr 18, 2018, 11:28:03 AM4/18/18
to ded...@googlegroups.com
Bruce,

Depending on how you want to handle the data from multiple files, you can either (a) get a list of filenames and loop through them, loading the data and applying your data wrangling to each in series, or you can (b) load all the data as data frames in a list (a list of data frames), then loop through the data frames (either combining them and then applying your wrangling, or wrangling and then combining the results of wrangling). Obviously, the former is more memory-efficient but only gives you access to the data in each file at any one time, while the latter is more memory-intensive but provides access to all the data at once.

A few examples of parts of this can be found in:

https://www.r-bloggers.com/looping-through-files/
https://stackoverflow.com/questions/5758084/loop-in-r-to-read-many-files

Regards,

Tom
signature.asc

Bruce Miller

unread,
Apr 18, 2018, 3:39:25 PM4/18/18
to ded...@googlegroups.com
Thanks guys,

I will revisit looping and reading a list of files and combining.
No help on R-Help to speak of and SO would not accept the question,
hence I took a shot on the Deducer list.

Bruce
Reply all
Reply to author
Forward
0 new messages