Why can't the pdf file created by gage (a R packge) be opened - r

I am trying to use Gage package implemented in R to analyze my RNA-seq data. I followed the tutorial and got my data.kegg.p file and I used the following script to generate the heatmap for the top gene set
for (gs in rownames(data.kegg.p$greater)[1]) {
outname = gsub(" |:|/", "_", substr(gs, 10, 100))
geneData(genes = kegg.gs[[gs]], exprs = essData, ref = 1,
samp = 2, outname = outname, txt = T, heatmap = T,
Colv = F, Rowv = F, dendrogram = "none", limit = 3, scatterplot = T)
}
I did get a pdf file named "NOD-like_receptor_signaling_pathway.geneData.heatmap.pdf", but when I open this file with acrobat reader or photoshop, it gives the error information that this file has been disrupted and cannot be recovered. Could anyone help check this file (https://www.dropbox.com/s/wrsml6n1pbrztnm/NOD-like_receptor_signaling_pathway.geneData.heatmap.pdf?dl=0) to see whether it is really disrupted and is it possible to find a way to recover it?
I also attached the R workspace file (https://www.dropbox.com/s/6n5m9x5hyk38ff1/A549.RData?dl=0). The object "a4" is the data with the format ready for gage analysis. It contains the data of the reference sample (nc) the treated sample (a549). It can be accepted by gage for analysis but generate the heatmap pdf file which cannot be opened (above). Would you mind helping me check whether these data can be properly used to generated the correct gage result?
Best regards.

I'm running into a similar problem myself. Not 100% sure but I think this problem occurs when there is no heatmap to plot. In my case, I was doing as.group comparison with ref and sample selections. I think the software treats this circumstance as a sample n of 1 and can't really show a differential heatmap. When I tried using 1ongroup setting, I was able to visualize the pdf file.

Related

Suppress graph output of a function [duplicate]

I am trying to turn off the display of plot in R.
I read Disable GUI, graphics devices in R but the only solution given is to write the plot to a file.
What if I don't want to pollute the workspace and what if I don't have write permission ?
I tried options(device=NULL) but it didn't work.
The context is the package NbClust : I want what NbClust() returns but I do not want to display the plot it does.
Thanks in advance !
edit : Here is a reproducible example using data from the rattle package :)
data(wine, package="rattle")
df <- scale (wine[-1])
library(NbClust)
# This produces a graph output which I don't want
nc <- NbClust(df, min.nc=2, max.nc=15, method="kmeans")
# This is the plot I want ;)
barplot(table(nc$Best.n[1,]),
xlab="Numer of Clusters", ylab="Number of Criteria",
main="Number of Clusters Chosen by 26 Criteria")
You can wrap the call in
pdf(file = NULL)
and
dev.off()
This sends all the output to a null file which effectively hides it.
Luckily it seems that NbClust is one giant messy function with some other functions in it and lots of icky looking code. The plotting is done in one of two places.
Create a copy of NbClust:
> MyNbClust = NbClust
and then edit this function. Change the header to:
MyNbClust <-
function (data, diss = "NULL", distance = "euclidean", min.nc = 2,
max.nc = 15, method = "ward", index = "all", alphaBeale = 0.1, plotetc=FALSE)
{
and then wrap the plotting code in if blocks. Around line 1588:
if(plotetc){
par(mfrow = c(1, 2))
[etc]
cat(paste(...
}
and similarly around line 1610. Save. Now use:
nc = MyNbClust(...etc....)
and you see no plots unless you add plotetc=TRUE.
Then ask the devs to include your patch.

How to display association rules using wordcloud in R?

I was trying to display the frequent association rules with tag cloud in R.
I have the association rules sorted in desc order and exported the results to a csv file with each rule in the first column. However, after I imported the csv file and tried to form a wordcloud, I got an error message: " Error in input$supoort : $ operator not defined for this S4 class"
I don't know what this means and how to get the wordcloud of frequent association rules, if possible.
Below is my code:
myData = read.transactions("data.csv", format = "basket",sep= ",", cols = 1, skip = 1)
rules <- apriori(myData, parameter = list(supp = 0.010, conf = 0.5, minlen = 2))
rules_supp <- sort(rules, by = "support", descreasing = TRUE)
inspect(rules_supp)
write(rules_supp,file = "rules_supp.csv", sep = ",", row.names = FALSE)
word <- read.csv(file = "rules_supp.csv")
wordcloud(words = word$rules, freq = word$support)
Try something like wordcloud(labels(rules)). However, wordcloud() will break the rule labels into words, and I am not sure that this is what you want.
There is wordcloud package you can use to make a word cloud graphics but there is a better way to display association rules in R.
You can use the R package arulesViz that you find here : https://cran.r-project.org/web/packages/arulesViz/vignettes/arulesViz.pdf
I have been using it for my paper I've published here https://link.springer.com/article/10.1007/s12652-017-0665-3
It helps you visualize the rules as correlation matrix or as a graph with nodes and oriented edges. Here are some of the graphics you can make.

Extracting values from a graph

I have a graph that is created by complex numbers from the function below. I would like to extract the resulting data points which correpond with the line from the data plot as to be able to work with a vector of data.
library(multitaper)
NW<-10
K<-5
x<-c(2,3,1,3,4,6,7,8,5,4,3,2,4,5,7,8,6,4,3,2,4,5,7,8,6,4,5,3,2,5,7,8,6,4,5,3,6,7,8,8,9,7,6,5,4,7)
resSpec <- spec.mtm(as.ts(x), k= K, nw=NW, nFFT = length(x),
centreWithSlepians = TRUE, Ftest = TRUE,
jackknife = FALSE, maxAdaptiveIterations = 100,
plot =FALSE, na.action = na.fail)
plot(resSpec)
What would be the best procedure. I have tried saving the plot in emf. I wanted to use package ReadImages which was I believe the right package. (however this was not available for R versiĆ³n 3.02 so I could not use it). What would be the correct procedure of saving and extracting and are there other packages and in what file types could I save the graph (as far as I can see R (OS windows) only permist emf.)
Any help welcomed

How to plot a large ctree() to avoid overlapping nodes

When I plotted the decision tree result from ctree() from party package, the font was too big and the box was also too big. They are overlapping other nodes.
Is there a way to customize the output from plot() so that the box and the font would be smaller ?
The short answer seems to be, no, you cannot change the font size, but there are some good other options.
I know of three possible solutions. First, you can change other parameters in the plot to make it more compact. Second, you can write it to a graphic file and view that file. Third, you can use an alternative implementation of ctree() in the partykit package, which is a newer package by some of the same authors.
Default Plot Example
library(party)
airq <- subset(airquality, !is.na(Ozone))
airct <- ctree(Ozone ~ ., data = airq,
controls = ctree_control(maxsurrogate = 3))
plot(airct) #default plot, some crowding with N hidden on leafs
Simplified plot
# simpler version of plot
plot(airct, type="simple", # no terminal plots
inner_panel=node_inner(airct,
abbreviate = TRUE, # short variable names
pval = FALSE, # no p-values
id = FALSE), # no id of node
terminal_panel=node_terminal(airct,
abbreviate = TRUE,
digits = 1, # few digits on numbers
fill = c("white"), # make box white not grey
id = FALSE)
)
This is somewhat better and one might be able to improve it further. To figure out these details, I originally did class(airct) which returned "BinaryTree". Armed with this info, I started reading ?plot.BinaryTree
Write to a file
A second simple solution is to write the plot to a file and then view the file. You may need to play with the settings to find the best fit.
png("airct.png", res=80, height=800, width=1600)
plot(airct)
dev.off()
Plot with partykit package instead
Finally, you can use a newer and not-yet-finished re-implementation of the party package by some of the same authors. At this point (Dec 2012), the only function they have re-done is ctree(). This version allows you to change font size.
library(partykit)
airct <- ctree(Ozone ~ ., data = airq)
class(airct) # different class from before
# "constparty" "party"
plot(airct, gp = gpar(fontsize = 6), # font size changed to 6
inner_panel=node_inner,
ip_args=list(
abbreviate = TRUE,
id = FALSE)
)
Here I have left the leafs in their default setting because I have frankly never figured out how to get it to work the way I want. I suspect this has to do with the fact that the package is incomplete (as of Dec 2012). You can read about the plot method starting with ?plot.party
Another option (that doesn't change what you want but does potentially solve the underlying problem) is to change the size of the figure itself, as I learned in my class for my assignment.
Replace the r in the below:
{r}
with:
{r, fig.width=X, fig.height=Y}
where the X and Y need to be replaced by numbers chosen by you depending on what size you think works better.
This website, talks about doing this in more detail and universally throughout the document.

Exporting individual pdf's for each plot created from a single file in R (using lattice)

So I have a fairly large dataset of GPS locations corresponding to different individuals at different times. It looks like a more complicated version of this...
ID________________Year________________Julian.date________________Distance
1_________________2003______________________15_____________________200
1_________________2004______________________20_____________________500
1_________________2005______________________24_____________________462
1_________________2006______________________28_____________________51
2_________________2002______________________12_____________________248
2_________________2003______________________15_____________________571
2_________________2004______________________16_____________________685
3_________________2003______________________20_____________________521
3_________________2004______________________25_____________________1251
3_________________2005______________________29_____________________225
3_________________2006______________________54_____________________144
What I am trying to do is separate the data out by year and individual. So each individual with have a boxplot of their Distances and the corresponding Julian date. I am able to create a massive pdf of all the plots (12X11) on one sheet using the lattice package (Separator is a column combining the ID and Year columns)..
> barchart(Julian.date~Distance|factor(Separator),data=data)
This isn't particularly helpful as I can't do much with such a massive pdf. So I tried restricting the number of plots per sheet to 1 using...
> barchart(Julian.date~Distance|factor(Separator),data=data,layout=c(1,1))
Which results in all the plots flying past me and none of them exporting to pdf. I have tried searching for a way to accomplish this, but so far no luck. If anyone knows a way of getting these to export as they fly past I would be extremely thankful.
So thanks in advance if anyone out there can help out. And if you need any more information, let me know, I tend not to use the terminology properly.
Ayden
I'm not sure what you are doing, or doing wrong as you don't show code, but using an example modified from ?barchart I see a PDF with multiple pages using this code:
foo <- barchart(yield ~ variety | site, data = barley,
groups = year, layout = c(1,1), stack = TRUE,
auto.key = list(space = "right"),
ylab = "Barley Yield (bushels/acre)",
scales = list(x = list(rot = 45)))
pdf("foo.pdf", onefile = TRUE)
print(foo)
dev.off()
onefile = TRUE should be the default and allows multiple pages in a single PDF. The other thing I do is print the barchart object in the pdf() wrapper; again, I don't think this is required if you are running R interactively but it will be needed if this is a batch or script based job.

Resources