# How to get arrowheads on vertical and horizontal lines with MeshFunctions in ListLinePlot?

I want to get such plot, using MeshFunctions

data = {{12, 2}, {5, 2}, {5, 4}, {14, 4}, {14, 1}, {1, 1}, {1, 5}, {18, 5}, {18, 0}};
ListLinePlot[data, PlotMarkers -> {Automatic, "Medium"}, MeshFunctions -> {#1 &}, Mesh -> 2, MeshStyle -> Opacity[0],


ListLinePlot[data, PlotMarkers -> {Automatic, "Medium"},  MeshFunctions -> {#2 &}, Mesh -> 2, MeshStyle -> Opacity[0],


But how to get arrowheads on both lines? Of course, I can combine two plots with Show. But is it possible to get one plot with arrowheads on vertical and horizontal lines? MeshFunctions -> {#1 &, #2 &} didn't help.

Instead of replacing a Line – which can go through multiple points – with a single Arrow, replace it with a sequence of multiple consecutive two-points arrows. Then you can tune the spacings with Mesh.

ListLinePlot[data, PlotMarkers -> {Automatic, "Medium"},
MeshFunctions -> {#1 &, #2 &}, Mesh -> {2, 2},
MeshStyle -> Opacity[0],
Line[pts_] :> (Arrow /@ Partition[pts, 2, 1])


To change every line into an arrow:

data = {{12, 2}, {5, 2}, {5, 4}, {14, 4}, {14, 1}, {1, 1}, {1,
5}, {18, 5}, {18, 0}};
ListLinePlot[data] /. Line[x__] :> Arrow[Partition[x, 2, 1]]


Or if you want several arrows on each line:

ListLinePlot[data] /.
Line[x__] :> {Arrow[Partition[x, 2, 1]],
Arrow[Partition[Riffle[#, Mean /@ Partition[#, 2, 1]] &[data], 2]]}