In JFreechart xySeries I want to plot the lines using a very dense set of points in order to show curves with precision, however, I want to plot the points with less density. For example, I have 100 data points each one is 1 unit apart on the x axis, but I only want to plot the point every 5 unit. I do,however, want the lines to be connected every 1 unit in order to show the curve with high density.
Is this possible?
You can subclass XYLineAndShapeRenderer and override getItemShapeVisible(int series, int item).
Related
I am plotting a food web ecological network with igraph and I am trying to avoid having my nodes to overlap.
The y-axis depends on the attributes of the nodes (i.e. the species trophic levels, varying between 1-3.52, no nodes between [1,2] by convention).
To do so, I calculate how many nodes there are within certain intervals of the y-axis range (1 to 4 with increments of 0.5).
If all nodes have the same size (defined by the user), I calculate the length of x-axis at each levels of y, as the sum of the size of the nodes (as if the nodes would be next to each other on a single axis):
xl <- (n nodes + 1 + 2 ) * size
I add 1 here since the nodes should be plotted from the certain of the nodes, so there is half a node on the left of the minima and right of the maxima of the x-axis. (The +2 is just to give a little space, and yes I know 1+2 =3 :) just to make the explanation easier).
I then calculate the break points on the x-axis calculating a sequence from half of the length I calculated above, centered around 0.
seq(-xl/2, xl/2,length.out = nnodes)
Doing so, each center of the nodes should be at a breakpoint on the x-axis with some distance between the nodes.
If the nodes have different sizes (defined by the user), I use the maximum size in the formula above so that I have enough space between each center of the nodes.
I combine the x-axis and y-axis coordinates as a matrix to use as my layout.
coordsp <- cbind(xcoord, TLsp)
I use rescale within the parameters of the plotting function.
plot(network, layout= coorsp,
rescale=TRUE,...)
I still get some overlap.
I tried using rescale = FALSE, specifying the x-axis and y-axis limits (range of the coordinates in coordsp) but the graph end up looking weird or the plotting window turns completely white.
I think the issue when rescale = TRUE is that it rescales the coordinates but not the size of the nodes, so that if they are too big for a window [-1,1]x[-1,1], the nodes end up overlapping.
Any guess on how to avoid overlap?
Thanks in advance
I have a large dataset which I need to plot in loglog scale in Gnuplot, like this:
set log xy
plot 'A_1D_l0.25_L1024_r0.dat' u 1:($2-512)
LogLogPlot of my datapoints
Text file with the datapoints
Datapoints on the x axis are equally spaced, but because of the logscale they get very dense on the right part of the graph, and as a result the output file (I finally export it in .tex) gets very large.
In linear scale, I would simply use the option every to reduce the number of points which get plotted. Is there a similar option for loglogscale, such that the plotted points appear equally spaced?
I am aware of a similar question which was raised a few years ago, but in my opinion the solution is unsatisfactory: plotted points are not equally spaced along the x-axis. I think this is a really unsophisticated problem which deserves a clearer solution.
As I understand it, you don't want to plot the actual data points; you just want to plot a line through them. But you want to keep the appearance of points rather than a line. Is that right?
set log xy
plot 'A_1D_l0.25_L1024_r0.dat' u 1:($2-512) with lines dashtype '.' lw 2
Amended answer
If it is important to present outliers/errors in the data set then you must not use every or any other technique that simply discards or skips most of the data points. In that case I would prefer the plot with points that you show in the original question, perhaps modified to represent each point as a dot rather than a cross. I will simulate this by modifying a single point in your 500000 point data set (first figure below). But I would also suggest that the presence of outliers is even more apparent if you plot with lines (second figure below).
Showing error bounds is another alternative for noisy data, but the options depend on what you have to work with in your data set. If you want to pursue that, please ask a separate question.
If you really want to reduce the number of data to be plotted, you might consider the following script.
s = 0.1 ### sampling interval in log scale
### (try 0.05 for more detail)
c = log10(0.01) ### a parameter used in sampler(x)
### which should be initialized by
### smaller value than any x in log scale
sampler(x) = (x>0 && log10(x)>=c) ? (c=ceil(log10(x)/s+0.5)*s, x) : NaN
set log xy
set grid xtics
plot 'A_1D_l0.25_L1024_r0.dat' using (sampler($1)):($2-512) with points pt 7 lt 1 notitle , \
'A_1D_l0.25_L1024_r0.dat' using 1:($2-512) with lines lt 1 notitle
This script samples the data in increments of roughly 0.1 on x-axis in log scale. It makes use of the property that points whose x value is evaluated as NaN in using are not drawn.
I am trying to stack multiple 2d plots into a single 3d plot in R.
For example, I want to try and put these plots
into a single 3d image. The z axis would be the biomass density, y axis be the size and the x axis be the time step (and then hopefully I could use a surface plot to join up all the lines). My aim is to try and show the wave travelling through the size over a long period of time instead of showing lots of images.
Does anyone know how to do this?
To illustrate:
x=rep(c(rep(1,4),rep(3,4),rep(6,4)),4)
y=rep(c(1,10,100,1000),12)
z=runif(48)
mydata=cbind(x,y,z)
scatterplot3d(mydata,pch=16,xlab="months",
ylab="parameter",zlab="values")
Here, x is number of months of which I have only three categories and y are values of four parameters used in my study. I want my x axis to show only 1,3,6 and the y axis to show only 1,10,100,1000 with equidistant separation on the axis. The present plot plots y axis as 0,200,400,600,800,1000. So my three data points pertaining to 1,10 and 100 values of y are restricted to a narrow zone.
set(gca,'yscale','log')
A log scale on the y-axis should give you what you're looking for in this instance. More generally, if you want axis points equidistant regardless of their value you might consider storing their values as a string and see what that does for you.
Is there a way to calculate an area of a filled countour like plot in r?
This image is just an example and not representative of my data. But I would, for example, want to calculate all areas above 1600. My data is in matrix for with speeds in each cell. The columns represent evenly spaced time intervals however my y axis or rows each represent a particular length and are not evenly spaced. The filled contour plot would be interpolating. I would like to bypass creating a color plot all together and just find the are of say speeds less than 35mph.