Alternatives to using text() to adding text to a plot - text

This may be a naive question, but I was wondering if there's a better way than using text() to adding text to a plot. Note, I'm also using layout() as well. Specifically, I have a section of a plot where I would like to add some text with headings followed by regular text.
text() is fine it seems for simple annotations, but to get the spacing right for several lines of text seems to require a lot of manual manipulation of the x and y and cex parameters. Any suggestions?

Here are some alternative options to consider:
- the gplots package has a textplot function to add some text output in a base graphics plot.
- plotrix has a function addtable2plot
- for grid graphics grid.text() is available and in gridExtra there is a function grid.table() (see, e.g., R-Wiki)

If you're using base graphics, then text() is probably your best bet, and fiddling with coordinates etc is part of the game. If you want to learn a new framework, the lattice package is a reworking of the basic approach to plotting in R. It be installed by default so help(package='lattice') will get you started.
Here's a pretty good guide (pdf) to graphics in general in R, with a substantial section on lattice:
download

Related

Making custom, fictional maps with D3.js

I'm kicking around an idea for a side project and am looking for advice on which direction to go in terms of technology. I've done some research already, but am still fairly confused as to what the realistic options are.
I'd like to make an interactive map based on a fictional world (think Middle Earth), including a timeline filter and a details section for additional information on an event or location.
Desired Features:
map on the left
details pane on the right
timeline slider/filter at bottom
Territories
color for political affiliation
displays details in details pane
labels
labels for cities
Hurdles:
Get a clean map image to work with
Map image into intermediate format (svg, geojson, topojson?)
Display map on webpage, style map, add animations, etc
Technologies
SVG
I'm pretty sure I could code all of this in SVG using events and boundaries. I've already been able to create SVG Paths from the image using GIMP, so converting the map into an SVG file seems plausible.
The issue with doing it this way is I would end up doing all the work the hard way when there seems to be lots of frameworks for this kind of thing already.
Kartograph
La Bella Italia is a very nice example and would serve as a good starting point. I love the trade route animations and the border styling with the glow filters.
The bonus here is that I know I can make an svg map, which is all this would need to get up and running.
My issue here is it doesn't seem like Kartograph is as rich of a platform as D3.js. I'm not sure if I can double dip and link some D3 stuff with the kartograph events. If I could, that might be the solution.
D3.js
The sliders, animations(hover and selection), and topojson seem like they would be perfect. But the main issue I have here is getting my image converted into a GeoJson format. From what I can tell these formats are strictly for Real World maps, using longitude/latitude.
So there you have it! I'm hoping there is some good news on how I might convert my map image into topojson so I can enjoy the benefits of D3.js. If not, I suppose I could just try kartograph and wire the events up with D3 controls.
Thoughts?
I'm currently writing my master thesis and I have the same topic like you had these days. I called my project Arda Maps. Feel free to ask me anything if have techonology questions.
I'm using the following frameworks/tools in my project:
QGIS
JQuery
D3.js
GeoJSON/TopoJSON
TimeGlider

Programming printable 2d-graphics

I want to create parametric graphics that can be printed exactly on any printer:
setup some constants,
create some points,
create some lines with different line widths and line patterns between those points (a little bit like creating 3d-objects with OpenScad).
A simple example would be to print the net of a cube that can be printed on paper, cut and glued together.
I see following options:
use a normal programming language like Java and a pdf-creation library (see this question)
program using SVG (can this be printed exactly?)
What other options do you see or can you share experiences about the above options?
I'm a web programmer primarily, so I would create html representing what I wanted printed (in your case, it would require using html canvas element with javascript), and then use an html-to-pdf library to make a PDF. I use PrinceXML, but wkhtmltopdf will also do the trick.
HTML Canvas: http://www.w3schools.com/tags/ref_canvas.asp
Prince XML: http://www.princexml.com/

Can I create a Calligraphy look with SVG?

is it possible to create a stroke with a dynamic width with SVG? I want to achieve a Calligraphy look like here, here or here.
Is this even possible? It seems customization of strokes in SVG is fairly limited. Even gradients in strokes seem to be non-trivial (see here).
There is a proposal to add into SVG standard a mechanism, that does exactly what you want:
http://www.w3.org/Graphics/SVG/WG/wiki/Proposals/Variable_width_stroke
http://lists.w3.org/Archives/Public/www-svg/2013May/0041.html
There's even an example implementation available here:
https://rawgit.com/birtles/curvy/master/index.html
It is, however, by no means official and we cannot be even sure it'll ever be.
Until then you'll need to stick to Bezier curves and object filling:
You can also use calligraphic fonts, for example - Tangerine available on Google CDN:
This approach requires less work since you don't need to draw everything from scratch, but then again, using third party fonts leaves you with little control over the final result.
You can't dynamically adjust the stroke of a path element. However you could draw a path, use a fill color on it instead of stroke, then double back upon the letters at a slight distance away from the original line.
Also, if you are using the SVG on the web then you can use css fonts on text elements. There are some pretty good cursive fonts that you can use for free... just check google web fonts.

How can I make a custom layout / change header background color … with Tex, Latex, ConTeXt?

currently I produce dynamically this document with Python Report Labs… to produce pdf documents.
Now, I would like try to produce this document with Tex / Latex / ConTeXt…
I've some questions :
how can I make the layout ?
how can I make header background color ?
how can I define my custom title (with blue box) ?
what is the better choice for my project : Latex or ConTeXt ?
What package I need to use ?
geometry ?
fancyhdr ?
Have you some example ? some resource ?
Yesterday, I've read many many documentation… and I don't found a solution / example for my questions.
Some useful packages apart from the fancyhdr you already mentioned are:
titlesec for more control over your section titles
booktabs for more control over table layout
PGF/TikZ for the graphics in your document, i.e., the page turn effect in the corner and maybe the blue boxes (although that might be considered a bit overkill :))
memoir for more control over your document layout, but the package is more book-oriented than you need probably
koma-script might be a good alternative for memoir but I'm not familiar with it so I don't know about its weaknesses
This is list is not exhaustive and I am not experienced enough in this kind of typesetting meets lay-out stuff to be of much help, but these are packages that come to my mind given your problem :).
Using inputenc there shouldn't be a problem typesetting Russian text.
Maybe the actual process will be easier in ConTeXt, it is more oriented towards control over your typesetting but I'm not familiar with it.
Good luck!
I'd certainly do this kind of think in Context rather than Latex: Context permits grid layout, and allows you to define layers for putting text and other graphics on top of background graphics. But as Pieter says, you could try using TikZ to do this with Latex.
Unicode is no barrier to regular Latex or Context: with either, just specify that you want to use utf-8 as input encoding.
If you do use Latex, don't have headers or footers, and allocate no vertical space for them either.
With Context:
how can I make the layout? — Use grid layout.
how can I make header background color? — Use \setupbackground
how can I define my custom title (with blue box) ? — I don't understand what you want to do here.
Everything you need to do this, except grid mode and how to put graphics in the background, is documented in Context an excursion. Grid mode is explained in the Context manual. Layers are a bit tricky to get to grips with, but Layers in the Context wiki is a good place to start.
With titlesec and color packages use this in LaTeX head (before \begin{document})
\usepackage{titlesec}
\usepackage{color}
% Colors
\definecolor{textcolor}{rgb}{.90,.95,1}
\definecolor{boxcolor}{rgb}{.94,.97,1}
% Header style
\titleformat{\section}
{\color{textcolor}\normalfont\Large\bfseries}
{}{1em}{{\color{boxcolor}\rule{0.35cm}{0.35cm}}\quad}
to make the blue box and change header color, font and remove numbering.

How to convert any text/font to its bezier path representation?

I have a bezier path library to draw complex bezier paths without problem. Now, I need to know how to read a text or font and extract its path information to draw it as a path instead of as text.
I came across a C application, FontForge. It does exactly what I need, picks any font and extract its path information. But what I need to know is how it does it to add that feature to my drawing library.
You can use windows GDI function GetGlyphOutline.
Alternatively use BeginPath, TextOut, EndPath and GetPath. You will obtain a list of straight segments and Beziers. See this article for inspiration (a bit dated, but relevant).

Resources