Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there some package to draw nice RDF graphs, such as the one below (taken from there)?

Can such a graph (with the same style) be produced in TikZ?

enter image description here

share|improve this question
1  
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. –  Jubobs Apr 5 '13 at 9:30
2  
The graph, per se, is not a problem: you can find several Q/A on how to do graphs (just use an ellipse shape), for example How to draw graphs in Latex?. For the "liquid" background, instead, you might follow as approach Highlight a group of nodes in a tikz tree. –  Claudio Fiandrino Apr 5 '13 at 9:30
    
Start from these examples texample.net/tikz/examples/feature/mindmaps and texample.net/tikz/examples/tag/diagrams –  alfC Apr 5 '13 at 9:53
    
Do you really insist on RDF? –  Speravir Apr 6 '13 at 20:35
1  
If my answer satisfies your needs could you consider to accept it? As a new user, I would courteously suggest you for the future to upvote all answers you find useful, including those to others' questions and to check/accept the best answers to your own questions by clicking the green tick on the left-hand side of the answer. This will help the community. –  Claudio Fiandrino Apr 11 '13 at 12:58

1 Answer 1

As first think I would start to define the style able to represent the vertices; we basically need:

  1. an ellipse;
  2. some size definitions;
  3. drawing the border thicker and setting the fill color brighter with respect to the border;
  4. making the text in white color;
  5. perhaps reduce a bit the size of the text font.

The style definition in TikZ can be done via \tikzset:

\tikzset{vertex style/.style={
    draw=#1,
    thick,
    fill=#1!70,
    text=white,
    ellipse,
    minimum width=2cm,
    minimum height=0.75cm,
    font=\small,
    outer sep=3pt, % the usage of this option will be clear later on
  },
}

Notice two things: this style receives an argument, the color and sets the fill color brighter by mixing the color with white. Secondly, the ellipse shape requires the library:

\usetikzlibrary{shapes.geometric}

Let's now create the first vertex. I would start with the "Righteous Kill" which has most connections departing from.

\documentclass[dvipsnames,png,border=10pt,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric} % required for the ellipse shape
\tikzset{vertex style/.style={
    draw=#1,
    thick,
    fill=#1!70,
    text=white,
    ellipse,
    minimum width=2cm,
    minimum height=0.75cm,
    font=\small,
    outer sep=3pt,
  },
}
\begin{document}
\begin{tikzpicture}
\node[vertex style=Turquoise] (Rk) {Righteous Kill};
\end{tikzpicture}
\end{document}

Beware of the option dvipsnames: it has been necessary to set this within the class options to prevent a possible option clash error since TikZ loads itself xcolor.

The node uses the style defined above setting its color (definition in the xcolor manual), its name (Rk) and its text {Righteous Kill}.

The result:

enter image description here

From now on, I won't display any time the preamble, but rather just the picture code.

Second step is to locate the other nodes. One might exploit lots of possibilities (using GraphViz, using the object-oriented module of PGF and build some custom class - see: Drawing relationships between elements of a database): here I use the positioning library of TikZ. Each vertex, therefore, will be located starting from the position of other vertices by referring to their names.

Notice: since each vertex needs to be connected to another one, the syntax

\node[options] (a) {text a} ... edge[options] node[options]{text conn} (b);

will connect the vertices a and b setting a label to the connection text conn. Extremely useful in this case. Indeed, let's start to add another node:

\begin{tikzpicture}[node distance=2.75cm,>=stealth']
\node[vertex style=Turquoise] (Rk) {Righteous Kill};

\node[vertex style=BurntOrange, above of=Rk,xshift=2em] (BD) {Bryan Dennehy}
 edge [<-,cyan!60!blue] node[text style,above]{starring} (Rk);
\end{tikzpicture}

The options node distance=2.75cm,>=stealth' concern the basic vertex distance and the type of the arrow tip used for the connection. Due to the arrow tip selected, the library arrows should be loaded.

Notice that the connection text requires a style: text style. Its definition is:

\tikzset{
  text style/.style={
    sloped, % the text will be parallel to the connection 
    text=black,
    font=\footnotesize,
    above
  }
}

The location of the new node is done via the options above of=Rk,xshift=2em: the first one sets the position in relation to the name of the previous node we created before, the second one shifts a bit on the right this position.

Result:

enter image description here

Once understood this mechanism, it is possible to locate all the other nodes:

\begin{tikzpicture}[node distance=2.75cm,>=stealth']
\node[vertex style=Turquoise] (Rk) {Righteous Kill};

\node[vertex style=BurntOrange, above of=Rk,xshift=2em] (BD) {Bryan Dennehy}
 edge [<-,cyan!60!blue] node[text style]{starring} (Rk);

\node[vertex style=BurntOrange, right=1.5cm of Rk,yshift=4ex] (AP) {Al Pacino}
 edge [<-,cyan!60!blue] node[text style]{starring} (Rk); 

\node[vertex style=red, below right of=Rk,xshift=2em] (JA) {John Avnet}
 edge [<-,cyan!60!blue] node[text style]{director} (Rk); 

 \node[vertex style=BurntOrange, right=1.5cm of Rk,yshift=-4ex] (RN) {Robert De Niro}
 edge [<-,cyan!60!blue] node[text style]{starring} (Rk); 

\node[vertex style=MidnightBlue, above right of=Rk,xshift=2em] (Dr) {Drama}
 edge [<-,cyan!60!blue] node[text style]{genre} (Rk); 

\node[vertex style=Maroon, below of=Rk,xshift=-2em] (Skf) {Serial Killer Films}
 edge [<-,cyan!60!blue] node[text style]{subject} (Rk);

\node[vertex style=Maroon, below right of=Skf] (Cf) {Crime Films}
 edge [<-,cyan!60!blue] node[text style]{broader} (Skf);
\end{tikzpicture}

enter image description here

Once this task is done, it is possible to start adding the "liquid" background around some vertices.

To place something in background the library backgrounds is of help, as well as the hobby library by Andrew Stacey to draw the smooth curve. Moreover, often some computation are needed, therefore also the library calc should be loaded.

The path definition should be done as follows: starting from the north of the node (Rk), one circumnavigates all possible anchors of the interested nodes to be highlighted. There are some automatic tools, see Hobby path realization in convex hull approach, but they can not be precise and fine tune things as some manual work can do. And, in this case this allows, to achieve a best result.

\begin{pgfonlayer}{background}
\draw[Maroon,fill=Maroon,dashed,fill opacity=0.1](Rk.north) 
to[closed,curve through={(Rk.north west).. (Rk.west) .. (Rk.south west) 
..($(Rk.south west)!0.5!(Skf.north)$) .. (Skf.north     west).. (Skf.west) 
.. (Skf.south west) .. ($(Skf.south)!0.75!(Cf.west)$) .. (Cf.west) 
.. (Cf.south west) .. (Cf.south) .. (Cf.south east) .. (Cf.east) 
.. ($(Cf.north east)!0.65!(Skf.south east)$) .. (Skf.east) 
.. (Skf.north east).. ($(Skf.north)!0.35!(Rk.south east)$) 
.. (Rk.south east) .. (Rk.east)..(Rk.north east)}](Rk.north);
\end{pgfonlayer}

More or less that's the code... but that's the result:

enter image description here

The mysterious option outer sep=3pt allows to not have the "liquid background" too much close to the border shape. And now it's all!

The complete code for reference:

\documentclass[dvipsnames,png,border=10pt,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric} % required for the ellipse shape
\usetikzlibrary{arrows, backgrounds, calc, hobby, positioning}

% this avoides some problem with the hobby implementation
% egreg's code from:
% http://www.guitex.org/home/it/forum/5-tex-e-latex/83195-la-libreria-hobby-tikz-non-funziona-piu#83203
\ExplSyntaxOn
\cs_if_exist:NF \prg_stepwise_function:nnnN { \cs_gset_eq:NN \prg_stepwise_function:nnnN \int_step_function:nnnN }
\cs_if_exist:NF \prg_stepwise_inline:nnnn { \cs_gset_eq:NN \prg_stepwise_inline:nnnn \int_step_inline:nnnn }
\ExplSyntaxOff

\tikzset{vertex style/.style={
    draw=#1,
    thick,
    fill=#1!70,
    text=white,
    ellipse,
    minimum width=2cm,
    minimum height=0.75cm,
    font=\small,
    outer sep=3pt,
  },
  text style/.style={
    sloped,
    text=black,
    font=\footnotesize,
    above
  }
}

\begin{document}
\begin{tikzpicture}[node distance=2.75cm,>=stealth']
\node[vertex style=Turquoise] (Rk) {Righteous Kill};

\node[vertex style=BurntOrange, above of=Rk,xshift=2em] (BD) {Bryan Dennehy}
 edge [<-,cyan!60!blue] node[text style]{starring} (Rk);

\node[vertex style=BurntOrange, right=1.5cm of Rk,yshift=4ex] (AP) {Al Pacino}
 edge [<-,cyan!60!blue] node[text style]{starring} (Rk); 

\node[vertex style=red, below right of=Rk,xshift=2em] (JA) {John Avnet}
 edge [<-,cyan!60!blue] node[text style]{director} (Rk); 

 \node[vertex style=BurntOrange, right=1.5cm of Rk,yshift=-4ex] (RN) {Robert De Niro}
 edge [<-,cyan!60!blue] node[text style]{starring} (Rk); 

\node[vertex style=MidnightBlue, above right of=Rk,xshift=2em] (Dr) {Drama}
 edge [<-,cyan!60!blue] node[text style]{genre} (Rk); 

\node[vertex style=Maroon, below of=Rk,xshift=-2em] (Skf) {Serial Killer Films}
 edge [<-,cyan!60!blue] node[text style]{subject} (Rk);

\node[vertex style=Maroon, below right of=Skf] (Cf) {Crime Films}
 edge [<-,cyan!60!blue] node[text style]{broader} (Skf);

\begin{pgfonlayer}{background}
\draw[Maroon,fill=Maroon,dashed,fill opacity=0.1](Rk.north) 
to[closed,curve through={(Rk.north west).. (Rk.west) .. (Rk.south west) 
..($(Rk.south west)!0.5!(Skf.north)$) .. (Skf.north     west).. (Skf.west) 
.. (Skf.south west) .. ($(Skf.south)!0.75!(Cf.west)$) .. (Cf.west) 
.. (Cf.south west) .. (Cf.south) .. (Cf.south east) .. (Cf.east) 
.. ($(Cf.north east)!0.65!(Skf.south east)$) .. (Skf.east) 
.. (Skf.north east).. ($(Skf.north)!0.35!(Rk.south east)$) 
.. (Rk.south east) .. (Rk.east)..(Rk.north east)}](Rk.north);
\end{pgfonlayer}

\end{tikzpicture}
\end{document}
share|improve this answer
    
I needed to install packages 1) hobby, 2) l3kernel, 3) xparse. –  Codera Purpa May 14 at 13:18
    
@CoderaPurpa: if you have a non complete distribution, yes. :) Personally, I always recommend to have it, because one does not have to think about requirements to make working any piece of code. –  Claudio Fiandrino May 14 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.