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

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!

Related

Using ggplot to plot a customizable table of data

This idea has been spurred by this work at Five Thirty Eight.
I'm not entirely sure that they used R, but the chart appears in a similar fashion to their other data viz. I looked around here, but couldn't find anything directly relating to this.
Is this kind of plot possible using ggplot?
Thanks for any and all help!
They do use R but their ggplot2 theme is semi-proprietary and they don't say what they use. People have attempted to recreate the theme
https://github.com/jrnold/ggthemes
After the graphs are created it then goes through an illustrative step to bring graphs together and make them more of a story.

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.

Replacing one d3 visualisation with another d3 visualisation in same place?

I'm using the datamaps library for d3 and I have asked the question unsuccessfully there on github so I wanted to cross-post it here.
What I'm trying to do is to visualise two measures – Income Inequality (Gini) and GDP per capita – in one world map and make it possible to switch between the two views.
I am almost there. Here is my example.
On the top you can choose which measure to look at and the updating works – except that the updated map is plotted underneath the previous one and not on top. This is happening even though I'm referring to the same id with both maps.
What am I missing?
Thanks for helping me!
EDIT: I managed to get it a little bit nicer – here is the updated version – but the maps are still printed over and over again below the space where they should appear.
I made a lot of these same mistakes when I first used D3. You have to use an enter(), update(), exit() pattern. There are lots of good tutorials on how to do that. Fundamentally, your structure is not setup correctly and is going to give you trouble.
For your code, you want to do the following:
Move the initial call to map() inside the map function.
Nest the map() function inside another function where you config your variables. You need to do all your global data/variable defining here.
Inside that config function, include d3.select(#radialbuttonname) and re run the map() function to update the chart on.click.
Inside the map function, you need to create functions for .data().enter(), .data.exit().remove(), and .data().transition(). That will replace the same SVG map area with a new map rather than just appending more svg's below.
You can change the tooltips and those other elements with if/then operators and remove() inside the map() function.
That should get you on your way..

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.

Flex Tree/Branch Diagramming/Graphics

I was wondering if anyone had access to source code that would allow me to draw lines between objects. I have examples of the standard one line between 2 objects.
What I'm looking for is an example of how to draw a branching line. I.e. Starts as a line coming from an object and then branches out to other objects. I don't want to draw multiple lines from the same object because I need the objects to be related and the lines to have a settable property.
The added issue is that I want the number of branches available to be settable by the user. But if I can find code that dooes the branching lines, it probably wouldnt be too hard to tweek.
Hopefully what I'm looking for makes sense. Any hints and tips would be much appreciated.
Check out the graphing libraries:
Birdeye's RaVis and Source
Flare and Source
Best,
Lance

Resources