I have on ODE of the form $\frac{dy}{dx}=f(x,y)$ that I managed to plot its solution in Matlab.
I want to add "direction of progress arrows" to the curves.
The curves illustrated below are the paramteric plot of x(t) and y(t), each having 1500 steps.
The black arrow seen on left has been inserted using the "Insert Arrow" option from the figure's window.
I want to add arrows like those in the black and white picture attached.
Is there any way to do it? Any help would be appreciated.
Not sure if you ever figured this out, however, one solution, though not elegant, could be to use the Plot with Direction Function from the MATLAB FEx.
After computing your ODE solution, you could take various points and use the above Plot with Direction function from the FEx. Below is some pseudo code which describes what I am talking about.
[x_sol, y_sol] = ODE_METHOD(#fcn,...);
x_Points4Arrow = x_sol([...]);
y_Points4Arrow =
% Plot ODE solution
for ind = 1:numel(y_Points4Arrow)
| hold on
| Plot With Direction(x_Points4Arrow(ind), y_Points4Arrow(ind));
| hold off
end
% Modify axes and anything else
You could even modify that function to take in the Line Properties - or just modify the code if you only want one color.
Related
I am conducting a ROC curve analysis in Stata. However, I am having trouble with the commands needed to get a plain white background plot.
I would like to:
remove the faint horizontal grid lines in the plot
remove the blue fill outside of the plot region
move the legend to the right upper-hand side (without a border/fill)
The following command was used to generate the ROC curve for a nonparametric ROC analysis without covariates:
roctab outcomedeath biomarkerlevel, binomial graph rlopts(lcolor(none) lpattern(shortdash)) legend(on)
As Nick implied, providing a reproducible example is the best way to help others on SO to help you.
Nevertheless, using the example from the roctab help file, we can see the standard Stata graph would look something like this:
webuse hanley, clear
roctab disease rating, graph
I like to use the scheme cleanplots (authored by Trenton Mize), which you can install with the command:
net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
You can then either set it as your permanent scheme, or call it explicitly when you call your graph. For example:
* Option 1: set to cleanplots permanently (or until I change to something else)
set scheme cleanplots, perm
* Option 2: set to cleanplots just for this session
set scheme cleanplots
*Option 3: call cleanplots explicitly by adding this option when you call your graph
, scheme(cleanplots)
You can then run the graph command, which will give you something like this:
roctab disease rating, graph scheme(cleanplots) //i'm assuming you went with Option 3
I personally think this cleans up the graph significantly (removing the blue fill around the plot, adding a bit more space between y-axis and x-axis titles and their corresponding axes, rotating the ylabels so they're more easily readable, etc.). To then get the other two items you want (moving the legend and removing the faint gridlines), you just need to add in a few more options:
roctab disease rating, graph legend(on ring(1) row(2) pos(2)) ylab(, nogrid) xlab(, nogrid)
Note the above removes both horizontal and vertical grid lines, but if you only want to remove the horizontal ones just delete the bit that reads xlab(, nogrid). And if you want to move the legend onto the plotregion (it's currently outside of it, see p.3 of this documentation), you should change the value of ring() from 1 to 0.
Finally it's worth noting that whenever a help file says that you can pass through twoway_options which the roctab help file does, you can use any twoway options. I accept that still leaves a lot of room for error and discovery, but still thought it was worth mentioning.
I would like to draw $3$ dimensional scatter plots, or more precisely I have a program that gives me the mass distribution in the unit cube with respect to a 3 dimensional equidistant grid. You can interpret this as a continuous relaxation of a $3$ dimensional assignment problem if you want.
Anyway this is just to give you a very brief background since my actual problem is not really concerned with the maths behind the procedure but with the visualization. I have:
$n$ points in the unit cube $[0,1]^3$
each of the $n$ points is assigned a "weight" between $0$ and $\frac1n$ (typically a lot of the weights coincide, if there are too many different values, i use the cut command to reduce the range to, say $60$ different values)
And I'd like to plot the $n$ points in a color which corresponds to their weight.
Now I found the rgl Package in R which allows me to do exactly that and also provides a very nice interactive plot window but it doesn't seem to allow a "col key" parameter, i.e. I cannot add a continuous color legend to my plot.
On the other hand the package plot3D provides a function to do a $3$ dimensional scatterplot and easily allows me to add the col key. However plot3D does not work with interactive plots but merely gives me the option to specify the angle at which I want to look at the cube. In a $3$D setting I strongly prefer the interactive alternative.
Now is there a way to automatically add a continuous color legend to an rgl plot? If not, do you know why this hasn't been implemented? Or would you solve my problem completely different altogether?
P.S. sorry for the formatting, I'm new to SO and the math environment "$" doesn't seem to work here.
The reason this hasn't been implemented is because until fairly recently it wasn't easy to have a static legend and a dynamic plot in the same window.
Now it's easy; there's a legend3d() function that might do what you want, but I think you probably want a different sort of legend than it will draw. If you know how to draw what you want in 2D, you can use the bgplot3d() function to put it in the background of your plot.
Both of those options give bitmapped legends. It would also be possible to do vector-based legends, but that would be quite a bit more work.
I'm trying to plot the cluster obtained from fuzzy c-means clustering.
The plot should look like this.
code for the plot
plot(data$Longitude, data$Latitude, main="Fuzzy C-Means",col=data$Revised, pch=16, cex=.6,
xlab="Longitude",ylab="Latitude")
library(maps)
map("state", add=T)
However, when I tried to use clusplot the plot is displaying in opposite direction(both top and bottom and left and right) as below.
I wanna know if there's a way to reverse the plot to show in the order as the above picture.
Also, for the very dense area, it's hard to find the ellipse label. I wanna know if there's a way to show the label inside the ellipse instead of outside.
code for 2nd pic
library(cluster)
clusplot(cbind(Geocode$Longitude, Geocode$Latitude), cluster, color=TRUE,shade=TRUE,
labels=4, lines=0,col.p=cluster,
xlab="Longitude",ylab="Latitude",cex=1)
clusplot is a function that performs a lot of magic for you. In particular it projects the data set - which happens in a way you don't like, unfortunately. (Also note the scales - it centered and scaled the data, too)
clusplot.default: Creates a bivariate plot visualizing a partition (clustering) of the data. All observation are represented by points in the plot, using principal components or multidimensional scaling.
As far as I can tell, clusplot doesn't have map support, but you will want such a map I guess...
While maybe you can use the s.x.2d parameter to specify the exact projection (and this way disable automatic scaling), it probably is still difficult to add the map. Maybe look at the source of clusplot instead, and take only the parts you want?
Is it possible to plot the following function with R?
$$\lim\limits _{x\to3^{+}}\, f(x)=2$$
$$\lim\limits _{x\to3^{-}}\, f(x)=1$$
Basically, I would like to see a plot with 2 curves. If possible how to make some circle (black or white) at the end of the curves... ?
Thank you
Define a piecewise continuous function:
ff <- function (xx) ifelse(xx<3,xx,xx+1)
Plot the first part of it, reserving enough space to plot the rest:
curve(expr=ff,from=0,to=2.999,xlim=c(0,6),ylim=c(0,7),xlab="",ylab="")
Add the second part:
curve(expr=ff,from=3,to=6,add=TRUE)
Add a little open circle:
points(3,ff(3),pch=21,bg="black")
Result:
I am in my way of finishing the graphs for a paper and decided (after a discussion on stats.stackoverflow), in order to transmit as much information as possible, to create the following graph that present both in the foreground the means and in the background the raw data:
However, one problem remains and that is overplotting. For example, the marked point looks like it reflects one data point, but in fact 5 data points exists with the same value at that place.
Therefore, I would like to know if there is a way to deal with overplotting in base graph using points as the function.
It would be ideal if e.g., the respective points get darker, or thicker or,...
Manually doing it is not an option (too many graphs and points like this). Furthermore, ggplot2 is also not what I want to learn to deal with this single problem (one reason is that I tend to like dual-axes what is not supprted in ggplot2).
Update: I wrote a function which automatically creates the above graphs and avoids overplotting by adding vertical or horizontal jitter (or both): check it out!
This function is now available as raw.means.plot and raw.means.plot2 in the plotrix package (on CRAN).
Standard approach is to add some noise to the data before plotting. R has a function jitter() which does exactly that. You could use it to add the necessary noise to the coordinates in your plot. eg:
X <- rep(1:10,10)
Z <- as.factor(sample(letters[1:10],100,replace=T))
plot(jitter(as.numeric(Z),factor=0.2),X,xaxt="n")
axis(1,at=1:10,labels=levels(Z))
Besides jittering, another good approach is alpha blending which you can obtain (on the graphics devices supporing it) as the fourth color parameter. I provided an example for 'overplotting' of two histograms in this SO question.
One additional idea for the general problem of showing the number of points is using a rug plot (rug function), this places small tick marks along the margin that can show how many points contribute (still use jittering or alpha blending for ties). This allows the actual points to show their true rather than jittered values, but the rug can then indicate which parts of the plot have more values.
For the example plot direct jittering or alpha blending is probably best, but in some other cases the rug plot can be useful.
You may also use sunflowerplot, while it would be hard to implement it here. I would use alpha-blending, as Dirk suggested.