Plots of different rows on the same graph - r

I found an interesting thread about plotting but I'm not happy with the answer. I would like to plot different amount of rows on the same graph. Just giving me the possibility to add as much rows as I want to.
I'd like to use glopts library but I am open for any other. First of all I want to plot those rows into pdf file. The script which I want to modify is:
which_rows <- c(12,156,4432) ## I want to choose which row I want to plot
pdf(file='Plots'.pdf)
x <- 1:(ncol(data_plot)-1) ## Can it be changed to use the name of the columns instead of pure numbers ?
for(i in which_rows){
## create new pdf page BUT I WANT TO PLOT IT ON THE SAME GRAPH!
plot(x=x,y=data_plot[i,-1],type='b',main=data_plot[i,1],xlab='columns',ylab='Intensity')
}
# closing pdf
dev.off()
Can you help me to modify this script to print just all of the rows which I decide on the same graph ? Would be great if you show me how I can jsut add new page in this pdf file using the other set of rows like which_rows2.
Of course each plot should has diffent colour or something.
Edit:

use points()to add points to the existing plot

Related

How would I make my boxplot show two columns instead of one

I'm trying to make a box plot that will show columns PSS_pre and PSS_post
At the moment I have the following code:
boxplot(PSS_post~intervention)
This code shows the column PSS_post, although I can change PSS_post to PSS_pre and it will show me the column for PSS_pre. How can I make it show me both colums at the same time?
Consider plotting a list with the 2 elements.
pp_list <- list(Pre = PSS_pre~intervention, post=PSS_post~intervention)
boxplot(pp_list)

How to add node size as legend in Cytoscape 3?

From an R function (cnetplot) I've obtained the following image which does not look very nice.
Therefore, I extracted the data from the R object and wrote a script to create an equivalent network data file that is readable by Cytoscape. The following equivalent plot from Cytoscape looks much better but the problem is that I am not able to add legends based on node size in Cytoscape as the R function did. I tried with Legend Creator app in cytoscspe but couldn't do it.
The original data and R code to reproduce the plots can be found in the following link.
ftp://ftp.lrz.de/transfer/Data_For_Plot/StackOverflow/
I looked into this Mapping nodes sizes and adding legends in cytoscape network, but in that case questioner already was able to load the node sizes as legends in cytoscape and moreover, he/she used a python package.
Any suggestions will highly be appreciated
Here's a little R script that will generate a min/max node size legend. You'll need to set the first variable to the name of the Visual Style in your network. This one works with the sample session file, "Yeast Perturbation.cys" if you want to test it there first.
If you are familiar with RCy3, then it should be self-explanatory. You can customize the positioning of the nodes, labels and label font size, etc. You can even adapt it to generate intermediate values (like in your example above) if you want.
NOTE: This adds nodes to your network. If you run a layout after adding these, then they will be moved! If you rely on node counts or connectivity measures, then these will affect those counts! Etc.
If you find this uesful, I might try to add it as helper function in the RCy3 package. Let me know if you have feedback or questions.
# https://bioconductor.org/packages/release/bioc/html/RCy3.html
library(RCy3)
# Set your current style name
style.name <- "galFiltered Style"
# Extract min and max node size
res<-cyrestGET(paste0("styles/",style.name,"/mappings/NODE_SIZE"))
size.col <- res$mappingColumn
min.size <- res$points[[1]]$equal
min.value <- res$points[[1]]$value
max.size <- res$points[[length(res$points)]]$equal
max.value <- res$points[[length(res$points)]]$value
# Prepare as data.frame
legend.df <-data.frame(c(min.size, max.size), c(min.value, max.value))
colnames(legend.df) <- c("legend.label",size.col)
rownames(legend.df) <- c("legend.size.min", "legend.size.max")
# Add legend nodes and data
addCyNodes(c("legend.size.min", "legend.size.max"))
loadTableData(legend.df)
# Style and position
setNodeColorBypass(c("legend.size.min", "legend.size.max"),"#000000")
setNodePropertyBypass(c("legend.size.min", "legend.size.max"),
c("E,W,l,5,0", "E,W,l,5,0"), # node_anchor, label_anchor, justification, x-offset, y-offset
"NODE_LABEL_POSITION")
setNodeLabelBypass(c("legend.size.min", "legend.size.max"), legend.df$legend.label)
setNodePropertyBypass("legend.size.max",
as.numeric(max.size)/2 + as.numeric(min.size)/2 + 10, # vertical spacing
"NODE_Y_LOCATION")
setNodeFontSizeBypass(c("legend.size.min", "legend.size.max"), c(20,20))

How can I plot more than one figure in the same JPEG file in R?

Here is the code for the plot I'm doing iteratively and storing it in different files.
lab=unique(train_train$PdDistrict)
lab=as.character(lab)
par(mfrow=c(1,2),mar=c(9,4,1,0))
for(i in 1:length(lab))
{
jpeg(file=mypath,quality=100,width=1024,height=768)
mypath=file.path("C:","Users","sujit_000","Desktop",paste("PDdistrict",i,".jpeg",sep=""))
a=plot(table(train_train[train_train$PdDistrict==lab[i],1]),las=2,main=lab[i])
dev.off()
}
The JPEG files I'm getting with this is 1 image per file like shown, but I want it to save two images per file.
Do you want two pages per file, each with a plot (as the comments suggest and correctly say won't work with jpeg) , or two plots in a single page/file?
Given the mfrow argument you used in par, I'll assume you want to latter. A couple of points to accomplish that:
Call par after jpeg, otherwise each call to jpeg is resetting the device options.
I imagine you actually want to define mypath before creating the device, otherwise it will be missing for the first file and the rest will be shifted by one.
You'll want to have two calls to plot, one for each of the plots you want together. Presumably you would also want to change the for-loop sequence to skip every other (assuming you want two consecutive ones plotted together).
Try something like this:
lab=unique(train_train$PdDistrict)
lab=as.character(lab)
## changed loop to every other
for(i in seq(1, length(lab), by=2))
{
## moved mypath before jpeg(), should mypath inclue both i and i+1 in name?
mypath=file.path("C:","Users","sujit_000","Desktop",paste("PDdistrict",i,".jpeg",sep=""))
jpeg(file=mypath,quality=100,width=1024,height=768)
## moved par() from outside of loop
par(mfrow=c(1,2),mar=c(9,4,1,0))
## removed unnecessary assignment of plot()
plot(table(train_train[train_train$PdDistrict==lab[i],1]),las=2,main=lab[i])
## added second plot for i+1
plot(table(train_train[train_train$PdDistrict==lab[i+1],1]),las=2,main=lab[i+1])
dev.off()
}
This will break on the last i+1 call if you have an odd number of plots, but that's a straightforward fix if necessary.

LocusZoom standalone change x-axis and use the plots in a script

I am using the standalone LocusZoom software,but I am having two problems:
I have to create a plot showing only position on the x-axis (not showing the genes). If I just use showGenes=FALSE with nothing else the genes still appear, but if I use rfrows=0 then the genes are not shown, but the problem is that also the x-axis label with the positions disappears. Is there a way to only show the position label? It looks like the only way to do this is to modify the original script...
Is there a way to use several plots created using LocusZoom in an R script to position many plots into one unique figure? (output is a pdf for now) There is an option listed in the LocusZoom webpage (http://genome.sph.umich.edu/wiki/LocusZoom_Standalone) called "prelude" but I cannot get more info on how to use it.
If you have any suggestions for either of these two issues it would be very helpful! Thanks!!

Graphite: multiple series with a single command

I would like to put two series in the same graph on the graphite dashboard. However, since the dashboard requires single-line commands I could not find a way that doesn't involve the use of a wildcard.
Here's an example of the two series I would like in the same graph:
sum(base.foo.bar.positive.*)
sum(base.foo.bar.negative.*)
I tried several separators but I could not get it to work. Any ideas?
You have a few options here...
Merge the 2 graphs on to the graph via the drag and drop in the dashboard
OR
Use the sumSeriesWithWildcards() function
Merge 2 or more wildcard matching
Open your first graph on the dashboard
Open your second graph on the same dashboard
Click and hold the second graph and drag it over the first graph
Use groupByNode() and wildcard matching
This is not as nice, and will not always work however you will be able to do this all in one line.
sumSeriesWithWildcards(base.foo.bar.{positive,negative}.*, 3)
This will do the following:
Select all all the graphs that match base.foo.bar.positive.* and base.foo.bar.negative.*
Sum the data by the node at position 3: positive, negative
You might want to have a read over the following page: http://graphite.readthedocs.org/en/1.0/functions.html

Resources