I'm using the pgfplots
package to generate a scatter chart with variable bubble sizes. Please, check the fallowing image:
However, I'm having the following issues:
- Node labels overlap. See for instance class1 and class2 labels.
- Bigger bubbles obscure the smaller ones. See for instance class4 and class3 bubbles.
- Also, class1's label remains behind class2's bubble.
Here I provide a minimal example of my code:
\documentclass[border = 1cm]{standalone}
\usepackage{tikz} % https://www.ctan.org/pkg/pgf
\usepackage{pgfplots} % https://www.ctan.org/pkg/pgfplots
% ->
\pgfplotsset{compat = newest}
\usetikzlibrary{plotmarks, positioning}
\begin{filecontents}{data.dat}
c1 c2 c3 c4
2 2 class1 10
2.3 2 class2 40
6.3 1.5 class3 10
7 2 class4 30
3 4 class5 10
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scatter/classes = {
class1={mark = *, green, opacity = .7},
class2={mark = *, blue, opacity = .7},
class3={mark = *, red, opacity = .7},
class4={mark = *, yellow, opacity = .7},
class5={mark = *, pink, opacity = .7}
}]
\addplot[
scatter,
only marks,
scatter src = explicit symbolic,
% Bubble sizes
visualization depends on = {\thisrow{c4} \as \perpointmarksize},
scatter/@pre marker code/.append style={/tikz/mark size = \perpointmarksize},
% Node labels
visualization depends on = {value \thisrow{c3} \as \perpointlabel},
nodes near coords* = {\perpointlabel},
every node near coord/.append style={
font = \tiny,
anchor = south
}
]
table[
x = c1,
y = c2,
meta = c3,
col sep = space
]{data.dat};
\end{axis}
\end{tikzpicture}
\end{document}
Is there a way to effectively solve the three issues mentioned above?