Justapigeon - 3 years ago 126
R Question

# R DiagrammeR Flush Subscript and Superscript within Labels

Long time reader, first time poster.

I am attempting to write mechner notation using DiagrammeR (through R Studio; everything is up to date; MacOS). Long term intention is to embed the code within a latex doc, but I'm taking this one step at a time. Currently, I cannot find the code necessary to force a subscript and superscript to be in-line with each other. So far, I have found this:

library(DiagrammeR)

grViz("
digraph dot {

graph [layout = dot, rankdir = LR]

node [fontname = Helvetica, shape = plaintext]
a [label = 'aA']
b [label = 'bA@_{2}@^{p}']
c [label = 'abC']

a -> b -> c
}")


Produces this.
But I need this.
I suppose the real question is how to properly format within those pesky quotations. I have yet to find a walkthrough on how to properly format (e.g., bold, italics, superscript) within the label field quotations. Suggestions?

I figured this out and forgot to post an answer! Here is the code that worked for me (Mac OSx; R Studio Sweave File, w/ pdfLaTeX enabled):

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{matrix}
\newcommand{\1}{\textbf} %to save space

\begin{document}
\SweaveOpts{concordance=TRUE}

%example 1
\par{\centering
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, nodes in empty cells, row
sep=1em,column sep=2em,minimum width=4em,nodes={anchor=center}]
{
a\1{A} & b\1{A}_{2}^{p} & ab\1{C} & \\
};
\draw [->] (m-1-1) -- (m-1-2);
\draw [->] (m-1-2) -- (m-1-3);

\end{tikzpicture}
\par}

%example 2
\par{\centering
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, nodes in empty cells, row
sep=1em,column sep=2em,minimum width=4em,nodes={anchor=center}]
{
t\1{S}_{A}^{D} & s\1{R}_{CR} & t\1{S}_{CR} & \\
};
\draw [->] (m-1-1) -- (m-1-2);
\draw [->] (m-1-2) -- (m-1-3);

\end{tikzpicture}
\par}

\end{document}


Here is the output

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download