The ContourPlot function in Mathematica automatically gets you a legend and contours with colors on the plot which are uniformly distributed ( for example, blue color from 0.1 to 0.2 function values, green from 0.2 to 0.3 and etc.) In my case, function, that I plot, has a large number of values in the 0.1 to 0.2 and only few from 0.2 to 1. If I want to distinguish better values from 0.1 to 0.2 and make several colors for this section, and make the values from 0.2 to 1 by one color, how should I do this?
I would use the Mathematica function Hue[z] to assign a color to your contours. To do this, you're going to use the option ColorFunction, like this:
ContourPlot[myFunction, {x,-10,10}, {y,-10,10}, ColorFunction -> Function[{f},Hue[g[f]]]]
In this code, g[f] is some function that maps the contour level to a hue (a value between 1 and 255). You said you wanted many values between 0 and 0.2, and only a few between 0.2 and 1, so I would use something like
g[f_] := 100*(5*f)^(1/4)
Obviously you can change this to fit. If this doesn't help, you may need to increase the number of contours, using the option Contours->n, where n is how many you want. Hope this helps!
Related
I've been struggling to get a plot that shows my data accurately, and spent a while getting gap.plot up and running. After doing so, I have an issue with labelling the points.
Just plotting my data ends up with this:
Plot of abundance data, basically two different tiers of data at ~38,000, and between 1 - 50
As you can see, that doesn't clearly show either the top or the bottom sections of my plots well enough to distinguish anything.
Using gap plot, I managed to get:
gap.plot of abundance data, 100 - 37000 missed, labels only appearing on the lower tier
The code for my two plots is pretty simple:
plot(counts.abund1,pch=".",main= "Repeat 1")
text(counts.abund1, labels=row.names(counts.abund1), cex= 1.5)
gap.plot(counts.abund1[,1],counts.abund1[,2],gap=c(100,38000),gap.axis="y",xlim=c(0,60),ylim=c(0,39000))
text(counts.abund1, labels=row.names(counts.abund1), cex= 1.5)
But I don't know why/can't figure out why the labels (which are just the letters that the points denote) are not being applied the same in the two plots.
I'm kind of out of my depth trying this bit, very little idea how to plot things like this nicely, never had data like it when learning.
The data this comes from is originally a large (10,000 x 10,000 matrix) that contains a random assortment of letters a to z, then has replacements and "speciation" or "immigration" which results in the first lot of letters at ~38,000, and the second lot normally below 50.
The code I run after getting that matrix to get the rank abundance is:
##Abundance 1
counts1 <- as.data.frame(as.list(table(neutral.v1)))
counts.abund1<-rankabundance(counts1)
With neutral.v1 being the matrix.
The data frame for counts.abund1 looks like (extremely poorly formatted, sorry):
rank abundance proportion plower pupper accumfreq logabun rankfreq
a 1 38795 3.9 NaN NaN 3.9 4.6 1.9
x 2 38759 3.9 NaN NaN 7.8 4.6 3.8
j 3 38649 3.9 NaN NaN 11.6 4.6 5.7
m 4 38639 3.9 NaN NaN 15.5 4.6 7.5
and continues for all the variables. I only use Rank and Abundance right now, with the a,x,j,m just the variable that applies to, and what I want to use as the labels on the plot.
Any advice would be really appreciated. I can't really shorten the code too much or provide the matrix because the type of data is quite specific, as are the quantities in a sense.
As I mentioned, I've been using gap.plot to just create a break in the axis, but if there are better solutions to plotting this type of data I'd be absolutely all ears.
Really sorry that this is a mess of a question, bit frazzled on the whole thing right now.
gap.plot() doesn't draw two plots but one plot by decreasing upper section's value, drawing additional box and rewriting axis tick labels. So, the upper region's y-coordinate is neither equivalent to original value nor axis tick labels. The real y-coordinate in upper region is "original value" - diff(gap).
gap.plot(counts.abund1[,1], counts.abund1[,2], gap=c(100,38000), gap.axis="y",
xlim=c(0,60), ylim=c(0,39000))
text(counts.abund1, labels=row.names(counts.abund1), cex= 1.5)
text(counts.abund1[,1], counts.abund1[,2] - diff(c(100, 38000)), labels=row.names(counts.abund1), cex=1.5)
# the example data I used
set.seed(1)
counts.abund1 <- data.frame(rank = 1:50,
abundance = c(rnorm(25, 38500, 100), rnorm(25, 30, 20)))
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")
Let's suppose my dataset is like this:
0 0.3
1 0.12
2 0.4
3 0.6
4 0.9
...
10 0.23
11 0.6
...
20 0.34
21 0.4
...
and I'd like to plot values of both columns only if $1 % 10 == 0, i.e., (0,0.3), (10,0.23), (20,0.34) and so on... Now, I've written the following conditional script:
plot "data.csv" using 1:(int($1)%10==0?$2:0/0) title 'r=1' with linespoints linewidth 3 linecolor rgb 'blue'
The problem is that lines are not shown, but only points.
This is because, for all rows where the condition is not satisfied, the corresponding value is undefined. Anyway, what I need is quite different; I want those specific values to be just ignored, not to set to undefined. Is there a way to do that just using gnuplot (not awk and so on)?
In case you have all intermediate steps, i.e., full data for number (which is suspect based on your axis labelled iterations), you best use the every option
plot "data.csv" every 10 with linespoints
Otherwise, I would use awk inside your script for simplicity
plot "<awk '$1%10==0' data8" with linespoints
The probably with your original script, is that the points are shown, but with value infinity. It is a feature that these lines are not shown.
Is there a way to have the names shown when use plot3d(rgl) in R to build a 3d graph, cause it's hard to locate which entry the sphere belongs to when I have many spheres to plot on the same coordinate. For example, I have the data:
x y z
A 0.1 -0.5 3.2
B -1.1 1.2 0.8
C 2.0 2.1 0.6
......
plot3d(data,type="s",radius=0.025)
But, I want to have the name A, B, C shown on the graph as it's easier to observe.
Or to have the name shown only when I put the mouse onto one specific sphere.
I have tried to use different colors, but when I have like 20 spheres, it seems it will run out of colors or colors are too close to distinguish.
There is a function text3d() in library rgl that can be used to plot texts inside plot. This example shows how to plot row names as texts.
plot3d(data,type="s",radius=0.025)
text3d(data$x,data$y,data$z,text=rownames(data))
You can also combine the use of text3d with identify3d() to identify points you want to label interactively with your mouse
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.