Is there some functionality to do arrow notation in R? I'm looking for something similar to hat(x), tilde(x), dot(x), ring(x) and bar(xy), mentioned in http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/plotmath.html.
[Update]
By "arrow notation", I mean vector notation. Like the one in the following image.
demo(plotmath) shows you the possibilities for drawing arrows in plot text. Examples include:
x %=>% y # double right arrow for implies
x %->% y # single right arrow for function mapping
Update based upon the comment:
There is no arrow accent available. You can hack one using atop(phantom(0) %->% phantom(0), x), but it doesn't look great because the arrow is too high up.
Related
I am trying to plot the solution curve from this page:
dynamicalsystem
But, I can't draw the arrow in the curve pointing to the origin, and the curve is not spiraling as well. Is something wrong with my code?
using MTH229, ForwardDiff, Plots, LaTeXStrings, SymPy
gr()
t = range(0, stop=21, length=10000)
x = #. exp(-2t)*cos(t)
y = #. exp(-2t)*sin(t)
plot(x, y, arrow = :closed, label=L"x(t)",
xlims=(-0.1,1), ylims=(-0.1,0.21))
You do not see a spiral, because the plot you have linked is not accurate (i.e. it has a wrong scale - most likely for didactic purposes). You can see that you have a spiral, by e.g. plotting the angle of the point plot(t, angle.(x + im * y)). The problem is that the plot absolute value of the points you plot gets very small very fast so these spirals are not visible.
Now the other issue is how to plot the arrow. The arrow in your case is just not visible because it is plotted at the end of your curve. I think (but maybe there are better ways to do it) that the simplest solution to pick a place to add it separately. For example after doing an initial plot add plot!(x[240:241], y[240:241], arrow=:closed) will add an extra arrow in the segment of your curve and the arrow will be visible (you just need to decide on the color of the arrow).
My questions is similar to one that's been asked but in a different language. I'm using plotly in python, to build dash web app dashboards and I have graphs with a y-axis range from negative values to positive values. I would like to leave the positive values black, but I would like to change the negative values to be red (preferably with parentheses around them as well, but the red color is the more important item).
From my research, it seems that there is no native way to do this. I'm up for a complicated solution if that's what it takes. When I inspect the element in the web interface, I can see the html code that shows the RGB values for the text of each tick, but I cannot seem to figure out where I can modify the colors independently of the other tick texts. I've started looking for the source file that is used to format these things so that I can potentially add the logic to it.
The similar question is here and it was asked for JavaScript: Plotly - I want to color each X Axis value in different color based on condition
Any help is appreciated.
I have a 1-dimensional list x in Maxima with 16 different elements, and plotted every possible product of two elements as a 3D plot:
g(u,v) := float('x[round(u)]*'x[round(v)]);
plot3d(g(u,v),[u,1,16],[v,1,16],[grid,15,15]);
Which yields this result:
http://i.stack.imgur.com/uKwfe.png
My desired result is having only the contour lines, i.e. the mesh. I don't want the coloured surface.
This seems like a trivial task, but the manual is very unclear on this. It says that usually, you already have only the mesh, but this isn't the case.
Using wxMaxima 12.04.0 on Windows.
Looks like the key is to get the Gnuplot output file to contain the line
set style data lines
Maxima has its own idea about "set style ..." which you can see by
set_plot_option ([plot_format, gnuplot]);
and then inspecting the output file ($HOME/maxout.gnuplot by default). I don't know how to convince Maxima to output a different style command. As a last resort you could edit maxout.gnuplot by hand.
g(u,v) := float('x[round(u)]*'x[round(v)]);
plot3d(g(u,v),[u,1,16],[v,1,16],[grid,15,15], [palette, false]);
The [palette, false] option turns off surface coloring and draws only the mesh. But you'll still get hidden line removal, which Maxima automatically turns on.
To get a transparent wire mesh, do this:
plot3d(g(u,v),[u,1,16],[v,1,16],[grid,15,15], [palette, false],
[gnuplot_postamble, "unset hidden3d;"]);
I'd like to create monochrome diagram/graph in octave using plot command.
That is why I'd like make different lines of graphs with using line style, for example dashed/dotted/dash-dotted styles. Standard plot suggests several styles for line, but none of them looks like listed variants.
EDIT-1:
Standard plot styles are inapplicable for my case: such styles as ":", "-.", "--" don't work, octave draws solid lines in any case. Furthermore, diamonds and squares (d and s options) are ugly and disproportionate big. May be it will be helpful information: I'm using Octave under Windows.
EDIT-2: For example, such command plot(A(:,1),A(:,2),"-.dk") gives me such (inapplicable !!!) figure
More specifically I want something like this (in part of line style)
(Picture from article: McCallum and K. Nigam. 1998. A comparison of event models for Naive Bayes text classification. In Proceedings of AAAI-98 Workshop on Learning for Text Categorization)
These can be set with the FMT argument of plot. Basically, these seem to be your options (see the manual entrey on line styles):
"-" solid lines
":" points
"-."dash followed by dot
"--" dashed
"none" no line (only markers)
There is also the option "." for dots but this is for the actual data points, not the line. So to recreate your picture, something like the following should work
plot (multinominal, "-dk", "MarkerFaceColor", "k")
hold on;
plot (mv-bernoulli, ":sk", "MarkerFaceColor", "k")
The syntax may look a bit strange but here's how to read it. For -dk, - is for solid line, d for diamond shaped marker, and k for black colour (b would be for blue). On :sk, it's dotted line and square shaped marker in black colour.
See the section on the manual for advanced plotting.
EDIT: see the comments below. This may not work in very old versions of Octave.
Well, I found a simple solution by myself (using Google ;))
For gaining monochrome diagram/graph with a different style of lines in Octave, we don't need to use plot's styles like "--" or "-." (because they do not work).
Just one thing we need is the command print. Monochrome figures can be created for example in the eps format:
print -deps "diagram.eps"
This gives me quite a nice picture:
I had the same problem and I think that the solution to make visible the line style is changing the linewidth. Many linestyles are not distinguished when the default linewidth value is used (which is 1).
Try the following code and see if it works:
x = ( 0:0.4:10 );
f = sin(x) .* exp(-4 .* x);
g = sin(x);
plot(x,f,'r:','linewidth',5,x,g,'-.','linewidth',2)
print(gcf,"PlotSimple.pdf")
Is there an function in R that does the same job as Matlab's "bar" function?
R does have a "barplot" function in the library graphics, however, it is not the same.
The Matlab bar(X,Y) (verbatim excerpt from MATLAB documentation) "draws a bar for each element in Y at locations specified in X, where X is a vector defining the x-axis intervals for the vertical bars." (emphasis mine)
However, the R barplot function does not allow one to specify locations.
Perhaps there is a method in ggplot2 that supports this? I am only able to find standard bar charts in ggplot2.
No, barplot is not the same as bar, but you should read the whole help. You can do many things to position the bars. The first is simply their order in Y. You could insert spaces if you wish (additional 0s). If you have X and Y then sort Y on X (Y[order(X)]) and plot it. If you need to change positions use the "space" and "width" arguments. It's not as straightforward as specifying X values I suppose but it's definitely more useful in most situations. Generally what you want to adjust is widths of bars and spaces between bars. Their position on the X-axis should be arbitrary. If the position on the X-axis is really meaningful then you should be using line plots, not bar graphs.
In R:
barplot(rbind(1:10, 2:11), beside=T, names.arg=1:10)
In MATLAB:
>> bar(1:10, [(1:10)' (2:11)'])
Read up on par . Then observe, for example:
x<-c(1,2,4,5,6)
y<-c(3,4,3,4,2)
plot(x,y,type='h',lwd=6)
Edit: yes, I know this doesn't (yet) plot multiple data sets, but I would hope you can see simple ways to make that happen, with spacings, colors, etc. specified to your exact liking :-)
Sounds vaguely like the R stepfun. On the other hand one would need to know what "draws a bar" means before saying it is not the same as barplot(..., horiz=TRUE) One would, of course, need to examine some more detailed evidence such as data and plots before arriving at a conclusion, however. #John Colby should be congratulated for adding some specificity to the discussion. The axis function is probably what Quant Guy needs education regarding.