manipulation of svg graphs with
play

Manipulation of SVG graphs with Stata Tim Morris , MRC Clinical - PowerPoint PPT Presentation

Manipulation of SVG graphs with Stata Tim Morris , MRC Clinical Trials Unit at UCL Robert Grant , BayesCamp 16 Nov 2017 Best feature in Stata 14? On upgrading Stata, one of the things I do first is to change bits with graph set . For example: .


  1. Manipulation of SVG graphs with Stata Tim Morris , MRC Clinical Trials Unit at UCL Robert Grant , BayesCamp 16 Nov 2017

  2. Best feature in Stata 14? On upgrading Stata, one of the things I do first is to change bits with graph set . For example: . graph set print logo off With version 14, I submitted graph set and spotted something unfamiliar…

  3. Best feature in Stata 14?

  4. Creating an SVG file . sysuse auto . twoway scatter price length [pw=weight] . graph export mygraph.svg, replace

  5. Result (using mrc graph scheme) 15,000 10,000 P ri ce 5,000 0 140 160 180 200 220 240 Length (in.)

  6. What is SVG ? S calable S o V ector V ery G raphics G ood

  7. Raster graphics (23kb .png)

  8. Vector graphics (10kb .svg)

  9. Read it

  10. Read it

  11. Edit it Let’s take a look at the file we created: auto.svg

  12. Edit it (from)

  13. Edit it (to)

  14. Edit it You don’t have to edit the text as I showed You can edit using software like Inkscape or Illustrator

  15. Manipulating SVG: principle • Produce an SVG file with Stata (14+) • Open it up and edit to make it even better • Receive praise and accolades from peers

  16. What can I manipulate? A lot, actually: • Add transparency to graph elements (ooh) • Embed images behind your graph (aah) • Create shapes Stata doesn’t allow ( phwoar) • Introduce interactive elements

  17. Why use Stata at all? Stata creates great SVG files. They are well organised (consistent order) and small. See: SVG from stats software: the good, the bad and the ugly goo.gl/q6no1L

  18. ‘Opacity’ opaque adjective not able to be seen through; not transparent. translucent adjective (of a substance) allowing light, but not detailed shapes, to pass through; semi-transparent.

  19. Translucency • Add to the style of objects • E.g stroke-opacity or fill-opacity • All done

  20. Translucency • As of Stata 15, you can do this within Stata.

  21. Translucency in action (1)

  22. Translucency in action (2)

  23. Add gradient to background

  24. Add gradient to background

  25. Embed an image/images • Hexagons are cool right now. • Putting a picture in a hexagon makes the picture cooler by association.

  26. Embed an image/images • Take an SVG file • Include a line referring to image: <image href =“tim.jpg” … /> • Include more such lines if you want • The image can be JPG, PNG, another SVG… probably GIF and more

  27. tim.jpg

  28. tim.jpg in an SVG hexagon

  29. tim.jpg in an SVG hexagon in same directory as the hexagon .svg file.

  30. Hexagonal binning • A ‘ hexbin ’ plot is a sort of bivariate histogram • Hexagons form a regular tessellating grid (and look better than triangles/rectangles) • Number of points covered by each hexagon is counted • Hexagon coloured/sized by count

  31. Hexbin using Stata Here, we are producing a plot that Stata does not • Set up a grid of hexagons in Stata and count the number of points in each hexagon’s territory • Output a scatterplot with points on the grid • Define a hexagon in SVG and replace each point output by Stata

  32. xkcd.com/1050/ To do hexagon counting, we will use some high-school algebra

  33. Hexbin √3 60 ° 60 ° 1 2 30 ° ½ √3/2

  34. Bivariate normal

  35. Better with translucency…

  36. Stata’s grid of hex centres

  37. Hexagons from SVG

  38. Waffle charts (similar concept)

  39. Maps We now have the tools to produce hexbin maps • Create hexbin using latitude and longitude • Find (or draw) a map and embed as an image behind your hexbin • Ensure they line up. This is hard: – Start with a scatterplot with a few key points and check that you can make these line up with map – Produce hexbin with same axis ranges, xsize, ysize, aspect etc.

  40. Interactivity • Add basic HTML before & after the SVG • Now you have a web page • Connect objects to controls like sliders, buttons, etc. with JavaScript

  41. Much more is possible! See: • Nadieh Bremer’s magic https://www.visualcinnamon.com/2016/04/svg- beyond-mere-shapes.html • Sarah Drasner’s animations What are your ideas?

  42. Thanks for listening

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend