I quite like hexagonal plots, and using Jake's code I managed to avoid falling back to R to render it.
Now, I do have a questions, how can I add a line plot that draws over it instead of under it?
MWE:
R code to generate bins:
# Load the data
library(maps)
data(world.cities)
# Load the hexbin package
library(hexbin)
# Generate hexbins, with the aspect ratio of the plot matching that of the data.
hbin<-hexbin(x=world.cities$long,y=world.cities$lat,xbins=100,shape=diff(range(world.cities$lat))/diff(range(world.cities$long)))
# Write the datafile. hcell2xy extracts the centroids of the hexagons
write.table(data.frame(hcell2xy(hbin),slot(hbin,"count")),row.name=F,file="testdata.csv")
tex code:
\documentclass{standalone}
\usepackage{siunitx}
\usepackage{pgfplots, pgfplotstable}
\sisetup{round-mode=places,round-precision=0}
\pgfdeclareplotmark{hexagon}
{%
\pgfpathmoveto{\pgfqpoint{0pt}{1.1547\pgfplotmarksize}}
\pgfpathlineto{\pgfqpointpolar{150}{1.1547\pgfplotmarksize}}
\pgfpathlineto{\pgfqpointpolar{210}{1.1547\pgfplotmarksize}}
\pgfpathlineto{\pgfqpointpolar{270}{1.1547\pgfplotmarksize}}
\pgfpathlineto{\pgfqpointpolar{330}{1.1547\pgfplotmarksize}}
\pgfpathlineto{\pgfqpointpolar{30}{1.1547\pgfplotmarksize}}
\pgfpathclose
\pgfusepathqfill
}
\pgfplotsset{
colormap={grayred}{color(0cm)=(black!10); color(1cm)=(red!75!black)}
}
\begin{document}
\begin{tikzpicture}[]
\begin{axis}[
enlargelimits=false,
colorbar, colormap name=grayred,
scale only axis,width=10cm,unit vector ratio*=1 1 1,
enlarge x limits={abs=2},enlarge y limits={abs=2},
xlabel=Longitude, ylabel=Latitude, xticklabel={\SI{\tick}{\degree}},yticklabel={\SI{\tick}{\degree}},
]
\addplot [
scatter, scatter/use mapped color={draw=mapped color, fill=mapped color},
scatter src=explicit,
only marks,
mark=hexagon,mark size=\pgfkeysvalueof{/pgfplots/width}/100/2
] table [meta index=2] {testdata.csv};
\addplot [blue, domain=-150:150] {0.5*x};
\end{axis}
\end{tikzpicture}
\end{document}
Question: how to get the blue line plot to draw over the custom plotmarks?


