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.

I am plotting points in a ternary diagram using pgfplots and the ternary axis environment. Each point does posses a 4th value (besides the 3 that are the coordinates). At the moment I am stating this 4th value as a node next to each plotted point. This comes with the problem that the minima/maxima of this value is not easy to spot as well as it is hard to read general trends. Also nodes can't reach outside of the ternary axis which leads to inconsistency with labeling points close to the axis.

I would like to have the points coloured according to their value (i.e. a value of 5 would be blue, 7.5 would be yellow and 10 would be red) this should be done gradually of course. Ideally I would like to have a fully coloured map with the space between the points interpolated.

Does anyone know of a way or at least a workaround to have the points coloured according to their 4th value?

Image:

enter image description here

LaTeX source:

http://depositfiles.com/files/5gaazfu5q

share|improve this question
1  
Also check the manual page 89 for nodes near coords example with colored markers. –  percusse Jan 26 '13 at 21:39
    
page 89 brought me close to the solution. The only thing missing now would be some sort of legend that shows which colour belongs to which number –  eject Jan 26 '13 at 22:58
1  
Also look for the colormap placement section of the manual. –  percusse Jan 26 '13 at 23:47

2 Answers 2

up vote 13 down vote accepted

a working example:

\documentclass [12pt]{scrartcl}
\usepackage [utf8x] {inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepgfplotslibrary{ternary, units}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.pathmorphing, pgfplots.ternary, pgfplots.units}

\begin{document}
\begin{tikzpicture}
 \begin{ternaryaxis}[colorbar, colormap/jet,
 xmin=0,
 xmax=100,
 ymin=0,
 ymax=100,
 zmin=0,
 zmax=100, 
 xlabel=component1,
ylabel=component2,
zlabel=component3,
label style={sloped},
minor tick num=3,
grid=both,
]

    \addplot3+[only marks, 
    point meta=\thisrow{myvalue}, %  uses ’point meta’ as color data.
     nodes near coords*={\tiny{\pgfmathprintnumber\myvalue}}, % does what it says
     visualization depends on={\thisrow{myvalue} \as \myvalue} %defines visualization dependency
     ] table {

x       y       z       myvalue
10      0       90      7.1
40      0       60      9.2
50      0       50      9.8
70      0       30      8.5
20      30      50      5.5
20      20      40      5
20      50      30      4.8
30      40      30      6.3
30      20      50      7.1
40      20      40      7.8
40      30      30      7.4
40      40      20      6.9
40      50      10      6.7
10      10      80      4.7
10      20      70      4.2
10      30      60      3.7
10      40      50      3.5
10      50      40      3.2
10      70      20      4.8
10      80      10      5.2
50      30      20      7.8
50      20      30      8.3
60      10      30      9
70      20      10      9.2
80      10      10      9.9
20      10      70      6.2
40      60      0       6.6
70      30      0       9.3
50      10      40      8.9
20      20      60      5.9
};

\end{ternaryaxis}
\end{tikzpicture}
\end{document}

Result:

Result

share|improve this answer
    
+1 for self-answering with the solution. I added the (nice) image. –  JLDiaz Jan 27 '13 at 1:33
    
Good solution! Note that you do not even need the "visualization dependency" in your current solution - its value is available as \pgfplotspointmeta anyway (i.e. your \myvalue is the same as \pgfplotspointmeta). –  Christian Feuersänger Jan 27 '13 at 8:12
    
Very nice diagram! I added it to the PGFplots example gallery. If you would like to show further plots made by you, let me know - this would be great! I noticed in your profile text, that you are experienced in plotting. Also, if you sometimes might think about a guest blog post oh pgfplots.net, to share some pgfplots tricks, I would be glad. –  Stefan Kottwitz Mar 17 at 11:06

The following can be achieved with R, knitr and ggtern (for producing ternary diagrams):

enter image description here

Produced with the following Rnw code, using data from .csv file (available HERE).

\documentclass[12pt,a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{helvet}
\renewcommand\familydefault{\sfdefault}
\usepackage{fancyhdr}
\pagestyle{empty}
\usepackage{subcaption}

\begin{document}
  <<SETUP,echo=FALSE>>=
    suppressMessages(library(ggtern))
    suppressMessages(library(tikzDevice))
    opts_chunk$set(fig.width=10,fig.height=9)
  @

\begin{figure}[p]
    <<PLOT,echo=FALSE,fig.align='center',dev='tikz'>>=
      df <- read.table("data2.csv",header=T)
      base <- ggtern(data=df,aes(x=y,y=x,z=z)) + 
        geom_point(aes(fill=myvalue),color="black",shape=21,size=5) + 
        geom_text(aes(label=myvalue),vjust=-1,size=3) + 
        theme_rgbw() +
        guides(fill=guide_legend()) + 
        scale_fill_gradient2(low="blue",mid="yellow",high="red",midpoint=mean(df$myvalue),breaks=c(3:10)) +
        theme(legend.position=c(0,1),
              legend.justification=c(0,1)) +
        labs(title="Example Ternary Plot",T="THS",L="LHS",R="RHS",fill="Density") +
        custom_percent("Percent")
      print(base)
    @
  \caption{Example Ternary Plot with Aesthetic Mapping}
\end{figure}

\end{document}

Using the tikzDevice, the font of the latex document is reflected in the plot itself.

share|improve this answer

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.