Thursday 18 April 2019

Resources to convert from SVG to RGML...

Helped by https://davetang.org/muse/2019/02/22/importing-vector-images-into-r/

So the best workflow, I have is SVG to EPS (encapsulated post script) through illustrator
EPS to RGML through PostScriptTrace
In this way icons can be used in images in R using the grid package...


https://github.com/sjp/grConvert

The RGML format is specific to the grImport package. It is a very simple graphics format that describes an image in terms that the R graphics system can understand. It will be described in more detail in later sections. ... The RGML formatin this example is roughly a one-to-one translation of the PostScript code.16 Apr 2009

https://www.rdocumentation.org/packages/grImport/versions/0.9-1.1/topics/PostScriptTrace

grImport::PostScriptTrace()
works and is maintained....



Inkscape - could be used in the command line...
http://tavmjong.free.fr/INKSCAPE/MANUAL/html/CommandLine.html

XSLT for converting from one kind of XML to another
https://github.com/ropensci/xslt
This may just be too difficult but who knows...

Ghostscript
https://stackoverflow.com/questions/9793120/how-to-covert-svg-to-eps-in-ghostscript
Converting from SVG to EPS...


Not sure about this but might be interesting
https://github.com/akrinke/svg2cairo


https://cairosvg.org/
Python library...

SVG to ps possibility...

https://stackoverflow.com/questions/9793120/how-to-covert-svg-to-eps-in-ghostscript


Recent grImport blog post...

Exploring this post https://davetang.org/muse/2019/02/22/importing-vector-images-into-r/

Interesting point about one of the commands:

head -17 shapes.eps.xml

It is a UNIX command not an R one!


Tuesday 16 April 2019

Reading about grImport2

So in 2013, Potter and Murrell developed grImport2.
https://sjp.co.nz/projects/grimport2/grImport2.html

This is to import SVG graphics into R.

Reading about this has revealed at key point:

"A complication with SVG is that unlike PostScript and PDF it does not require the use of a physical coordinate system (e.g. points). This, among other things (such as attribute precedence), complicates the process of importing an SVG image. However, if we restrict the SVG we support to the SVG that is generated by the Cairo graphics library [10], then we know that the SVG images that we import are guaranteed to belong to a common coordinate system and other features of the image will be flattened, making it easier to parse. In particular, this means that grImport2 does not need to parse all of the SVG image format, only the subset of SVG that Cairo generates. Furthermore, because Cairo is is a supported graphics renderer for many open source libraries that import vector images, we know that it is possible for many input formats to be mapped to the Cairo SVG subset of SVG."

Thus there is more than one kind of SVG!

Work flow seems to be:

R> # Converting the image
R> library(grConvert)
R> convertPicture("nzflag-original.svg", "nzflag-cairo.svg")
R> # Reading it into R
R> library(grImport2)
R> nzflag <- readPicture("nzflag-cairo.svg")

So convertPicture() into cairo svg first and then readPicture()

Got to be worth trying...

Monday 15 April 2019

Going back to personograph

So the speed of the rendering of the images in personograph may indicate that it is best to just
made adaptations to this line of work.

The icons in this package are in the inst folder.
They are named:
1.ps.xml

and represent post script files turned into xml with the grImport package.

https://cran.r-project.org/web/packages/grImport/vignettes/import.pdf

Adding extra icons should be quite feasible. Find a postscript file (PS) and use grImport to turn it into xml.

However, is it possible to plot with different icons? I suspect so but I will need to learn more coding to make that certain, I think.

Second issue would seem to be to be able to change the number of rows - the dimensions argument does this...
Again this shouldn't be too difficult, I think...



Finally adding the random element might be a bit more difficult...



So here is some more reading:
https://davetang.org/muse/2019/02/22/importing-vector-images-into-r/

icon arrays

Online tool:
http://www.iconarray.com/why


So R seems to have an options here:




Are these the same as waffle plots:

Also there is this:



Some reading:



Other links:












Monday 18 March 2019

More D3 map resources

https://medium.com/@andybarefoot/making-a-map-using-d3-js-8aa3637304ee

https://observablehq.com/@d3/cylindrical-stereographic

http://bl.ocks.org/micahstubbs/8e15870eb432a21f0bc4d3d527b2d14f

https://bl.ocks.org/ChumaA/385a269db46ae56444772b62f1ae82bf

https://medium.com/@mbostock/command-line-cartography-part-1-897aa8f8ca2c

This was particularly good:
https://medium.com/@amy.degenaro/introduction-to-digital-cartography-geojson-and-d3-js-c27f066aa84

https://codepen.io/brennanpincardiff/pen/Rdyprp

https://codepen.io/brennanpincardiff/pen/zbjZGg

https://github.com/brennanpincardiff/rhiwbina_codeclub_javascript/blob/master/world.md

Exploring FreeCodeCamp

Found FreeCodeCamp via:
https://medium.freecodecamp.org/object-oriented-programming-concepts-21bb035f7260


This is interesting.

I’m learning a little:
  • About different html tags
  • Internal anchors
  • Anchor tag attributes.
  • Form and input anchors
  • Button anchors
  • Radio buttons & checkboxes

There is a lot here…

I wonder if it’s worth sharing with Code Club members or if it’s all a bit serious?

Form and input anchors
<form action="/submit-cat-photo">
<input type="text" placeholder="cat photo URL" required>
</form>

Button anchors
<button type="submit">this button submits the form</button>
Inside the form anchors…


FINISHED!!
Took a couple of hours, I think...

Monday 4 March 2019

Revisit Noun Project package...

So I want to revisit the Noun Project package that we worked on last November to at least try to make it workable.

I want to be able to turn a downloaded set of icons into a ggplot visualisation or a Rmarkdown report.

Aim: download cat icon, download dog icon, download fish icon - make graph of number of households in UK with those pets...
The waffle project might be useful.
We shall see...

Where to start?
So my Github repo is 7 commits ahead, 2 commits behind...

Also there is a branch entitled paul_writes_vignette...
Would be good to try to integrate all of this and work out how it can all work together. 

More to do....

Bar charts with animals...

ggtextures

https://github.com/clauswilke/ggtextures


Friday 15 February 2019

Data and tidyverse links

These were useful:

https://rstudio-pubs-static.s3.amazonaws.com/282405_e280f5f0073544d7be417cde893d78d0.html

https://stackoverflow.com/questions/6639713/how-do-i-strip-dollar-signs-from-data-escape-special-characters-in-r

https://stackoverflow.com/questions/42493381/dplyr-select-columns-by-position-in-nse

https://www.mentalhealth.org.uk/statistics

https://ourworldindata.org/cancer

https://ourworldindata.org/cancer-death-rates-are-falling-five-year-survival-rates-are-rising

http://dyingforacure.org/blogs/misled-cancer-progress/


Monday 4 February 2019

Revisiting javascript and D3

Ok, so this is a bit of a blast from the past.

There are a couple of Code Club students that are interested in HTML and generally manipulating web content.

I've agreed to have a look at Javascript and try to organise a few lessons.

Revising my old D3 code skills....

Some things to think about:


Code can be run on https://jsfiddle.net
This gives an online play area...
Three windows with HTML, CSS and Javascript
and then a result window.

JQuery Biolerplate can be added.
D3 can be added as a library here:
Currently No_Library but easy to add stuff...


There are some key things to understand:

  • <div></div>
  • var
  • chaining
Some nice simple tutorial...



Probably worth encouraging students to work through both of the HTML projects or at least the one with Javascript...

Revisiting some simple D3 sources: https://www.dashingd3js.com/adding-an-svg-element



Observable might be an interesting tool but probably not right now...
https://beta.observablehq.com/playground


Other Javascript libraries are available:
https://blog.bitsrc.io/11-javascript-charts-and-data-visualization-libraries-for-2018-f01a283a5727

N.B. The trinket for the the Code Club project gives the answer - NOT good!

Other resources: 
  • https://projects.raspberrypi.org/en/coderdojo
  • https://bost.ocks.org/mike/bar/
  • https://projects.raspberrypi.org/en/projects?software[]=html-css-javascript
  • CSS Colour picker: https://www.quackit.com/css/css_color_codes.cfm



Wednesday 30 January 2019

no visible binding for global variable

Solution here for "no visible binding for global variable"
seems to be to declare the variables at the beginning of the function.
A bit of a work around.

Suggested here:
https://github.com/STAT545-UBC/Discussion/issues/451