I am making a volcano plot in R. I have a huge range of pvalues and log2fold changes. I set an xlim and ylim because I want to focus in on the central region of the plot. However, naturally setting my limits excludes some of my data. I would like to have the data outside of my axes limits displayed at my limits. So for example, a fold change of 4 would be displayed as a point just outside of my xlim of 2.
with(mydata, plot(ExpLogRatio, -log10(Expr_p_value), pch=20, main = "Volcano Plot",xlim=c(-2,2),ylim=c(0,40)))
this works but cuts out some of my datapoints (those with fold change above 2 and less than -2 and with pvalue of less than -log10(40)
if I understand correctly, I'd just use pmin and pmax to limit your values, e.g.:
values = seq(-3, 3, len=21)
pmin(pmax(values, -2), 2)
gives back:
[1] -2.0 -2.0 -2.0 -2.0 -1.8 -1.5 -1.2 -0.9 -0.6 -0.3 0.0 0.3 0.6 0.9 1.2
[16] 1.5 1.8 2.0 2.0 2.0 2.0
i.e. it's limited values to the range (-2, +2).
applying this to your data, you'd do something like:
with(mydata, {
lratio <- pmin(pmax(ExpLogRatio, -2.1), 2.1)
pch <- ifelse(ExpLogRatio == lratio, 20, 4)
plot(lratio, -log10(Expr_p_value), pch=pch, ylim=c(0, 40))
})
you'll probably want to set xlab and main to set titles, but I've not included that to keep the answer tidier. also extending this to the y-axis would obviously be easy
note I've also changed the plotting point style to indicate which points were truncated
Related
I am trying to compare the results of a measurement from different collaborations using gnuplot. The plot should ideally look like this:
I can't figure out how to plot the different results one on top of the other, with the labels on the right. I would be really grateful if anyone could help me.
I show two approaches, depending of your data file. Two possible structures are data01.dat
# data01.dat
alpha error
1.0 0.2
2.0 0.2
1.5 0.2
or data02.dat
# data02.dat
Collab alpha error
1 1.0 0.2
2 2.0 0.2
3 1.5 0.2
Using the data01-structure:
reset
set encoding utf8
set terminal wxt size 480,600 font "Times New Roman,10"
set tics out nomirror
set xlabel "{/:Italic=12 α}"
set link y2
unset ytics
set y2range [:] reverse
set y2tics 1
set format y2 "Collaboration %g"
set offsets graph 0.1, 0.1, 0.5, 0.5
plot "data01.dat" u 1:0:2 w xerrorbars pt 7 not
Using the data02-structure almost all is the same, except the plot command.
plot "data02.dat" u 2:1:3 w xerrorbars pt 7 not
The results.
I hope be useful.
I'm using Gnuplot 4.6. I have data files each containing 3 columns of data: X coordinate, Y coordinate and temperature. I wish to make an animation of plots of temperature as a function of X and Y coordinates. For this I'm using the following script:
set pm3d map; set palette;
do for [n=0:200] {splot sprintf("Temperature.%04d.dbl", n) binary array=100:100:1 form="%double" title 'file number'.n}
My problem is with the fact that after a few plots, the distribution of colors changes, both in the plot and in the legend. This makes the reading from the graph really hard.
I consulted the following post:
gnuplot heat map color range
and since the range of the temperature variable is from 0.0 to 1.2 I thought to use:
set zrange [0.0:1.2]; set cbrange [0.0:1.2];
but it doesn't help and the temperature color continues to be autoscaled from plot to plot. Any suggestions?
In addition to setting cbrange, you could try defining your own palette by
set palette defined (0 "black",\
0.2 "red",\
0.4 "orange-red",\
0.6 "orange",\
0.8 "yellow",\
1.0 "light-green",\
1.2 "green")
Or if you want discrete values:
set palette defined (0 "black",\
0.2 "black",\
0.2 "red",\
0.4 "red",\
0.4 "orange-red",\
0.6 "orange-red",\
0.6 "orange",\
0.8 "orange",\
0.8 "yellow",\
1.0 "yellow",\
1.0 "light-green",\
1.2 "light-green")
I have a plot in R with both x and y-axes tick labels looking like this:
-1.5 -1.0 -0.5 0.0 0.5 1.0
How can I remove the -1.5, -0.5, 0.5 tickmarks/labels?
How can I remove the decimal from the remaining labels? (i.e. -1.0 to become -1).
So, a plot like this is what I hear you describing:
plot(seq(-1.5, 1.1, 0.5),seq(-1.5, 1, 0.5))
Adding the xaxp and yaxp vectors will let you fine-tune the labeling:
plot(seq(-1.5, 1.1, 0.5),seq(-1.5, 1, 0.5), xaxp=c(-1,1,2), yaxp=c(-1,1,2))
The input to xaxp is "A vector of the form c(x1, x2, n) giving the coordinates of the extreme tick marks and the number of intervals between tick-marks when par("xlog") is false." See the help page for par{graphics} for more details
What is the best way to plot a graph with a continuous variable on the x axis and the ratio of success on the y axis for example with data:
x <- c(.1,.3,.4,.5,.6,.3,.4,.6,.7,.8)
y <- c(0,0,0,0,0,1,1,1,1,1)
df <- cbind(x,y)
plot(x,y)
I want to see values on the y as a ratio instead of 0 and 1. But, need to aggregate x values since the data is continuous and not .1,.2, etc.
For .3 on the x for examle, the point should have a y value of .5 (instead of one on 1, and one on 0).
I want to model success but I don't know what type of model to use, linear or something else. I would like to see the shape of the curve and then find a proper fit.
Thanks!
OK I'm guessing you mean this?
> rowMeans(table(x,y))
0.1 0.3 0.4 0.5 0.6 0.7 0.8
0.5 1.0 1.0 0.5 1.0 0.5 0.5
> R=rowMeans(table(x,y))
> plot(names(R),R, type='h', ylim=c(0,1))
I have a question about the package gplots. I want to use the function heatmap.2 and therefore I want to change my symmetric point in color key from 0 to 1. Normally when symkey=TRUE and you use the col=redgreen(), a colorbar is created where the colors are managed like this:
red = -2 to -0.5
black=-0.5 to 0.5
green= 0.5 to 2
Now i want to create a colorbar like this:
red= -1 to 0.8
black= 0.8 to 1.2
green= 1.2 to 3
Is something like this possible?
Thank you!
If you look at the heatmap.2 help file, it looks like you want the breaks argument. From the help file:
breaks (optional) Either a numeric vector indicating the splitting points for binning x into colors, or a integer number of break points to be used, in which case the break points will be spaced equally between min(x) and max(x)
So, you use breaks to specify the cutoff points for each colour. e.g.:
library(gplots)
# make up a bunch of random data from -1, -.9, -.8, ..., 2.9, 3
# 10x10
x = matrix(sample(seq(-1,3,by=.1),100,replace=TRUE),ncol=10)
# plot. We want -1 to 0.8 being red, 0.8 to 1.2 being black, 1.2 to 3 being green.
heatmap.2(x, col=redgreen, breaks=c(-1,0.8,1.2,3))
The crucial bit is the breaks=c(-1,0.8,1.2,3) being your cutoffs.