SVGAnnotation to create tool tips for each value in R heatmaps - r

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.

Related

How to turn a spatial plot in R into an ArcGIS layer

So I hope I can clearly communicate my issue. Since I'm fairly new to R and ArcGIS I may miss some obvious things.
Basically, I'm using R to process spatial data to make a canopy height model and detect tree tops. That parts fine. I then make a watershed segment plot using forestTools package, and visually it looks great, but how do I export that as a file I can add into ArcGIS?
I'll copy some of the code that goes into what I'm discussing.
Basically, I just followed this guide's supplemental material to get the tree detection https://www.degruyter.com/document/doi/10.1515/geo-2020-0290/html?lang=en.
With that done, I then used the forestTools package to creat an interesting segmentation polygon grid on the map. https://www.rdocumentation.org/packages/ForestTools/versions/0.2.5/topics/mcws
This is quickly the plotting code to get visualized what I want.
[1]: https://i.stack.imgur.com/7Y0EF.png
This is what the map looks like with those plotted.
[2]: https://i.stack.imgur.com/Kdfl6.png
The layer that I want to bring solo to ArcGIS is that last plot the mcws one. I'll show a pic of that as well here.
[3]: https://i.stack.imgur.com/3PKfk.png
Is there a way that I can export that as a .shp or .tif?
Any help would be wonderful and much appreciated!
Nvmd I figured it out.
What you have to do is use the Raster package to export a shapefile.
raster::shapefile(site2_ttops,"Products/site2plot_ttops.shp")

What type of data do I need for maplines in R highcharter?

I'm trying to add a mapline object to a highcharter graph (ideally using hcmap as a base)--in my case, so county borders can look different than state borders.
I've seen the solution listed here, but it doesn't work for me--indeed, running the answer's example code fails to create different lines for states and counties. Meanwhile, the more complex code shown here does work, but I'm not sure what it's doing under the hood, or how I could use its method to create a mapline object of state boundaries. What kind of data do I need to add a working "mapline" series? Does anyone know a good source for one for state boundaries?
Any help would be appreciated!

Manually Drawing Curves on R like Paint

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.

Can R create a barplot image with clickable bars to insert on a webpage?

I know how to create a barplot, and how to stick it on a webpage; e.g, using hwriteImage in the hwriter package.
What I'd like is for each bar to be a region which highlights on mouseover, and where each bar has a different link when clicked. Similar to this map of the U.S. using the jQuery maphilight plugin, but for a barplot rather than a map. I imagine R could calculate the coordinates of the regions around each bar, generate the HTML AREA tag etc and pass this to maphilight quite easily. Has it been done already? I searched but no luck so far.
Have a look here, which summarises a couple of methods: rggobi and iplots. rggobi looks pretty promising, though maybe the installation looks a bit involved. iplots is only good for scatter plots.
Some other options (I think these are strongest ones at the moment):
googleVis
The googleVis package interfaces with the google charts API: try demo(googleVis) and the third & fourth one are bar chart (there could be more). It has the advantage of being pretty simple to get started with, although these are not R graphics:
df=data.frame(country=c("US", "GB", "BR"), val1=c(10,13,14), val2=c(23,12,32))
Column <- gvisColumnChart(df)
plot(Column)
gridSVG
The gridSVG exports the current grid graphics to an .svg file that can be included into a webpage. Unlike googleVis, it's R graphics (so you can use grid/ggplot2 which are more familiar). It looks like you may have to know some Javascript to further embellish your plots though (e.g. to animate on mouse over, you use grid.garnish(...,onmouseover=...)).
There's some example code you can try here (The really awesome ones are here - usually clicking on the "SVG file" link will have the full interactivity/animation.) (This one is a scatterplot where the points highlight when you move your mouse over them).
As I said - have a look at the package pages, demos, examples, etc to see which suits you.

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