Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • interactive graphs - possible on D3 and R , is it possible in stata?

    Hi

    Has anyone ever tried creating interactive graphs? Similar to here:
    https://pclambert.net/interactivegra...ife_expectency
    This was created in D3 - however I am currently stuck to working on a remote platform with no internet so I can not use D3
    I know it's possible in R with ggplot - again I only have stata on my remote platform

    I found a couple of websites (see below)

    esentially the concept is all the same, creating static images and then morphing them into a GIf.

    However, on the website of P Lambert, he is able to drag the cursor along the line and have their respective values for survival.

    Is this possible with stata because from my search I gather that this is not possible however, I am resorting to state of us to check if there is someone who knows about a solution
    https://blog.stata.com/2014/03/24/ho...s-using-stata/

    https://www.techtips.surveydesign.co...-stata-graphic
    Last edited by Martin Imelda Borg; 08 Nov 2023, 10:47.

  • #2
    Essentially, it seems you are asking whether it is possible to animate Stata graphics. There are a few issues here. The first issue is that, supposing this is possible, you would probably need to run the animation code in an active Stata environment. As far as I know, it would not be possible to export a dynamic Stata plot to something like JavaScript/HTML to imbed in a web page.

    The second issue is more substantial. Basically, animations work by redrawing the plot over and over again. Each draw represents a frame in the animation. The problem is that Stata's plotting system relies heavily on inheritance - an object oriented programing feature that provides powerful abstractions at the expense of efficiency. Stata's plotting library is too slow to completely redraw the entire plot in the way that makes it look like an animation. There is a possible work around that might be worth exploring. Say you want to create an animation. You can make a series of edits to the plot in the graphic editor using the record feature that follow the steps of the animation you want to make. This should create a file with a .grec extension. The .grec file is a plain text file with some undocumented commands that allow you edit an active plot on the fly. You can make one of these files to reverse engineer the commands you'll need to build an animation. I did some preliminary testing trying to make animations like this last year and it was much faster than redrawing the entire plot.

    There is a third issue. If you really want to reproduce that d3 plot, you notice there are mouse "on hover" events: basically, things that happen as you move your mouse over the plot. I've looked for this kind of low-level keyboard/mouse control a few times (I've even looked through the Mata documentation for this) but I can't find a reference to this kind of event hook anywhere. So mouse events like this may not be possible.

    As a complete aside, I've worked with D3 before. It's great! I love the dynamic animations. JavaScript was the first language I ever learned and I always enjoy going back to it and learning new things. Sorry you wont be able to take advantage of D3 here.

    Comment


    • #3
      Look at Robert Grant's work on this, demonstrating Stata possibilities (and comparing with R): http://www.robertgrantstats.co.uk/animatedgraphs/line.html . Robert gave a presentation about this stuff at the UK Stata Conference a few years ago; you'll be able to find it at the UK section of the Meetings section of StataCorp webpages

      Comment


      • #4
        I didn't see your edit before you posted.

        esentially the concept is all the same, creating static images and then morphing them into a GIf.
        Well yeah. Another way to approach this problem is to generate a series of still plots that together animate your plot. Looks like that's what Robert Grant is doing with FFMPEG.

        Comment


        • #5
          Stephen Jenkins i really enjoy reading your work. I’ve seen robert grant’s work but just to be sure there’s no option with regards to hovering the cursor over the graph and obtaining values right ?

          Daniel - with regards to D3… it works by importing the csv file/ excel into D3 right ?
          Last edited by Martin Imelda Borg; 08 Nov 2023, 12:03.

          Comment


          • #6
            Well, that's how it starts, but building a d3 plot is a bit more involved than that. D3 is a JavaScript library. Observable is a piece of software designed to build d3 plots. It looks like a nice piece of software, but I've never used it. I just consume d3 directly as a javascript library. Doing it my way comes with other problems though. For example, how should you host the data so the browser can read it? I usually convert tabular data to JSON, then work with the JSON as a JavaScript object literal. Observable seems like it should be much easier, but I'd bet there is still a fair amount of JavaScript programming involved, especially if you want to get sophisticated user-interaction behavior like in the plot you linked to in #1.

            Comment


            • #7
              I'm not sure if terminology is standardised but I think of dynamic graphs -- you see a movie, not a single still, a.k.a. animation -- and interactive graphs -- you can ask a question, or you can tweak a setting, without re-running a command because the graphic itself contains enough information and offers handles to do that.

              Like Stephen Jenkins, I guess, I've heard and enjoyed Robert Grant's presentations without ever feeling that I wanted do something similar. There are fields of science, engineering and medicine where both dynamic and interactive graphics are not only good ideas, but even essential tools. But my own practice remains conservative in this sense: I write papers with static Figures, and I give presentations with static slides, and that is where I stop. I am not the only one.

              I've attend many Stata users' meetings which traditionally end with something called "Wishes and grumbles" where the wishes are users' suggestions of what they want StataCorp to do. I can't recall any clamour for the company to implement either. I do not know far that is because (a) people just don't need it (b) if they need it they are already using something else (c) they realise that it needs a completely different graphics engine.

              Comment


              • #8
                Well, I do think Robert Grant's graphs are too cool.
                Do file available here:
                http://www.robertgrantstats.co.uk/an...illing_line.do

                Comment

                Working...
                X