Manually Drawing Curves on R like Paint - r

I was trying to allow the user to give a curve as input for some analysis. Is there a package that can be used in this regard? Basically, a GUI like paint wherein the user can draw a simple curve and which would be stored in R as a set of data points or as an equation if its a simple curve.
Thanks
Gopher

Reading mouse input
Below is a list of sample approaches to first the problem, from the most complex to simplest (IMHO).
I would recommend that you have a look at the
qtpaint
package.
Less laborious solution may involve looking at the way interactive
plots in Shiny are handled. Using the click option would
enable you to get the mouse cursor position. Together with the Shiny
framework this would provide a convenient wrapper to get mouse input
from a user.
Finally, third approach could rely on making use of the locator function available in the graphics package. Depending on what you intend to do, this may be the simplest solution as you could then use read values to inform generation of your graphic.
Generating graphics
Assuming that you got your values via the locator functionality you could attempt to draw your line using segments. It would be a little fiddly as you would have to translate your coordinates to some placement of the dot in your desired chart but this wouldn't computationally too taxing, just a matter of bring mouse pointer values to some x/y values on the chart.
If you care to update your post with a sample code and reproducible attempts of your previous work, I bet the question will receive more replies. You may find this discussion on making a reproducible example in R helpful.

Related

How to keep camera orientation fixed in an interactive 3D plot in R/Shiny

I have a 3D rgl plot that users can modify based on some inputs (you can see it in action at https://magalab.shinyapps.io/rgl_test/). But every time the user modifies the input settings, renderer returns to the initial orientation to redraw the model. I want to keep the orientation consistent between updates. I know how to do that in rgl, and there is already another similar question
(Shiny RGL Plot3D: Keep Plot View Orientation On Replot), which did not receive any answer.
There is potentially a relevant topic at shiny app rglwidget get userMatrix to generate another plot with same rotation, but I don't want to see the userMatrix, simply pass it to the open3d().
Unfortunately, I am not familiar with Javascript and Shiny to achieve this. Any pointers will be much appreciated.
In the very newest rgl (version 0.99.18, currently only on R-forge), there's a function called shinyGetPar3d that is designed to do what you want. See example(shinyGetPar3d) for a demonstration of how to use it.

Successive pictures on R

I have a code to plot a world map with a meteorological field for one moment (or one measure).
Is it possible to successively plot the map for different moments (for i from 1 to 125) in order to view a sort of video when we run the code?
Yes, look at the animation package.
It can creates an animated gif for you (as well as other tricks). There are live examples you can look at as eg Buffon's needle, a CLT demo and much more.
The package abstracts away some of the OS-dependent layers. If you know the basics, you can of course just call the corresponding tool from the imagemagick project which is likely to be available on OS of choice too.

SVGAnnotation to create tool tips for each value in R heatmaps

I'd like to create a heat map in R that I want to use on a website. I stumbled upon the SVGAnnotation package which seems to be very nice to process SVG graphics in R to make them more interactive. First, I was planning to add tool tips for each cell in the heatmap - if the user hovers over the cell, the value of this cell should pop up. However, I am fighting with SVGAnnotation for more than 3 hours now, reading and trying things, and I can't get it to work.
I would appreciate any help on the SVGAnnotation tool tip function. But I would also very much appreciate alternatives to SVGAnnotation to add some activity to my R SVG heatmap.
So, what I have got so far looks like this:
library(SVGAnnotation)
data(mtcars)
cars <- as.matrix(mtcars)
map <- svgPlot(heatmap(cars))
addToolTips(map, ...) # problem
saveXML(map, "cars.svg")
My problem is the addToolTips function itself, I guess. Intuitively, I would simply insert the data matrix, i.e., cars, but this does not work and R gets stuck (it's calculating, but doesn't return anything, I waited 50 minutes)
EDIT:
After some more online research, I found a good example of what I want to achieve: http://online.wsj.com/article/SB125993225142676615.html#articleTabs=interactive
This heat map looks really great, and the interactive features (tool tips) work very well. I am wondering how they did that. To me, it looks like the graphic was done in R using the ggplot package.
I wrote a command line tool that can do exactly that if you are still interested to add tool tips to your heat map. It runs in Windows/Linux/MacOS terminals. All you need as input is the heat map as svg file and the data table/matrix that you used as input to create your heat map as csv or other text file.

Raster map vs alternative

I recently found this web page Crime in Downtown Houston that I'm interested in reproducing. This is my first learning experience with mapping in R and thus lack the vocabulary and understanding necessary to make appropriate decisions.
At the end of the page David Kahle states:
One last point might be helpful. In making these kinds of plots, one
might tempted to use the map raster file itself as a background. This
method can be used to make map plots much more quickly than the
methods described above. However, the method has one very significant
disadvantage which, if not handled properly, can destroy the entire
purpose of using the map.
In very plain English what is the difference between the raster file
approach and his approach?
Does the RgoogleMaps package have the ability to produce these types
of high quality maps as seen on the page I referenced above that
calls a google map into R?
I ask not because I lack information but the opposite. There's too much and I want to make a good decision(s) about the approach to pursue so I'm not wasting my time on outdated or inefficient techniques.
Feel free to pass along any readings you think would benefit me.
Thank you in advance for your direction.
Basically, you had two options at the time this plot was made:
draw the map as a layer using geom_tile, where each pixel of the image is mapped onto the x,y axes (slow but accurate)
add a background image to the plot, as a purely "cosmetic" annotation. This method is faster, because you can use grid.raster which draws images more efficiently, but the image is not constrained by the axes of the plotting region. In other words, you have to manually adjust the x and y axes limits to make sure that the image corresponds to the actual positions on the plot.
Now, I would suggest you look at the new annotation_raster in ggplot2 v. 0.9.0. It should have the advantage of speed and leaner output files, and still conform to the data space of the plot. I believe that this function, as well as geom_raster and annotation_map did not exist when David made those plots.

Plotting large numbers with R, but not all numbers are being shown

I am trying to render 739455 data point on a graph using R, but on the x-axis I can not view all those numbers, is there a way I can do that?
I am new to R.
Thank you
As others suggested, try hist, hexbin, plot(density(node)), as these are standard methods for dealing with more points than pixels. (I like to set hist with the parameter breaks = "FD" - it tends to have better breakpoints than the default setting.)
Where you may find some joy is in using the iplots package, an interactive plotting package. The corresponding commands include ihist, iplot, and more. As you have a Mac, the more recent Acinonyx package may be even more fun. You can zoom in and out quite easily. I recommend starting with the iplots package as it has more documentation and a nice site.
If you have a data frame with several variables, not just node, then being able to link the different plots such that brushing points in one plot highlights them in another will make the whole process more stimulating and efficient.
That's not to say that you should ignore hexbin and the other ideas - those are still very useful. Be sure to check out the options for hexbin, e.g. ?hexbin.

Resources