Psxy does not connect closely space line segment as expected

Aloha. I’m plotting a flight path that should have connected transect lines on alternating lines. Using the same data, in R, ggplot produces the expected behavior (see endpoints). However, psxy does not connect the end points between lines and I can’t figure out why not the data are in the correct order. Must be missing a magic incantation. Mahalo for any help.

R

psxy

Hi John,

What can we say without seeing the data? But I bet psxy is doing the right thing the data is telling it to do. If you want the lines connected, they cannot be broken, either in segments or having separating NaNs.

Aloha, Joaquim. Hope all is well. Here’s a snippet of the data before it is rotated and translated. At row 31, you can see where the end of the first segment is and the correct coordinates for the next point (AFAIK). However, psxy does not connect them; yet ggplot does. What am I doing wrong?

J.

df0
[,1] [,2]
[1,] 1 0
[2,] 1 1000
[3,] 1 2000
[4,] 1 3000
[5,] 1 4000
[6,] 1 5000
[7,] 1 6000
[8,] 1 7000
[9,] 1 8000
[10,] 1 9000
[11,] 1 10000
[12,] 1 11000
[13,] 1 12000
[14,] 1 13000
[15,] 1 14000
[16,] 1 15000
[17,] 1 16000
[18,] 1 17000
[19,] 1 18000
[20,] 1 19000
[21,] 1 20000
[22,] 1 21000
[23,] 1 22000
[24,] 1 23000
[25,] 1 24000
[26,] 1 25000
[27,] 1 26000
[28,] 1 27000
[29,] 1 28000
[30,] 1 29000
[31,] 1 30000
[32,] 1001 30000
[33,] 1001 29000
[34,] 1001 28000
[35,] 1001 27000
[36,] 1001 26000
[37,] 1001 25000
[38,] 1001 24000
[39,] 1001 23000
[40,] 1001 22000
[41,] 1001 21000
[42,] 1001 20000
[43,] 1001 19000
[44,] 1001 18000
[45,] 1001 17000
[46,] 1001 16000
[47,] 1001 15000
[48,] 1001 14000
[49,] 1001 13000
[50,] 1001 12000
[51,] 1001 11000
[52,] 1001 10000
[53,] 1001 9000
[54,] 1001 8000
[55,] 1001 7000
[56,] 1001 6000
[57,] 1001 5000
[58,] 1001 4000
[59,] 1001 3000
[60,] 1001 2000
[61,] 1001 1000
[62,] 1001 0
[63,] 2001 0
[64,] 2001 1000
[65,] 2001 2000
[66,] 2001 3000
[67,] 2001 4000
[68,] 2001 5000
[69,] 2001 6000
[70,] 2001 7000
[71,] 2001 8000
[72,] 2001 9000
[73,] 2001 10000
[74,] 2001 11000
[75,] 2001 12000
[76,] 2001 13000
[77,] 2001 14000
[78,] 2001 15000
[79,] 2001 16000
[80,] 2001 17000
[81,] 2001 18000
[82,] 2001 19000
[83,] 2001 20000
[84,] 2001 21000
[85,] 2001 22000
[86,] 2001 23000
[87,] 2001 24000
[88,] 2001 25000
[89,] 2001 26000
[90,] 2001 27000
[91,] 2001 28000
[92,] 2001 29000
[93,] 2001 30000
[94,] 3001 30000
[95,] 3001 29000
[96,] 3001 28000
[97,] 3001 27000
[98,] 3001 26000
[99,] 3001 25000
[100,] 3001 24000
[101,] 3001 23000
[102,] 3001 22000
[103,] 3001 21000
[104,] 3001 20000
[105,] 3001 19000
[106,] 3001 18000
[107,] 3001 17000
[108,] 3001 16000
[109,] 3001 15000
[110,] 3001 14000
[111,] 3001 13000
[112,] 3001 12000
[113,] 3001 11000
[114,] 3001 10000
[115,] 3001 9000
[116,] 3001 8000
[117,] 3001 7000
[118,] 3001 6000
[119,] 3001 5000
[120,] 3001 4000
[121,] 3001 3000
[122,] 3001 2000
[123,] 3001 1000
[124,] 3001 0
[125,] 4001 0

Also, have also used much coarser spacing so the data snippet would be easier to read. I have actually plotted this coarse version but I will if you think that’s helpful.

I have NOT actually plotted the coarse version; is what I meant to say.

Well try and see it working. Just picked the rows 1, 31, 32 & 33 (the example file is unusable with those [xx,]

julia> viz([1 0; 1 30000; 1001 30000; 1001 29000])

Hi @hellyj,
hm. Maybe posting your codes in GMT and R helps us to find what is going wrong here.
For me, you data looks correct at the change from one line to the next line.

Right. Mahalo for the replies. I’ve attached the whole data file and listed, here, the code I’m using. Very much appreciate the review. $FP26904B is the input data file. I’ve also tried the -L option with no apparent effect.

J.

TICK=-Ba5000f5000:“X”:/a5000f1000:“Y”:WesN
PROJECTION=-JX25c
REGION=-R737000/762060/2296000/2330000 # West Maui
gmt6 grdimage surface2.nc $PROJECTION $REGION -Csurface2.cpt -K > $FIGURE.ps
gmt6 grdcontour surface2.nc $PROJECTION $REGION -C100 -K -O >> $FIGURE.ps
gmt6 psxy $FP26904B $PROJECTION $REGION -Gblack -K -O >> $FIGURE.ps
gmt6 psbasemap $REGION $PROJECTION $TICK -Lx5.25i/0.5i+c0+w21000+l(m) -K -O >> $FIGURE.ps
gmt6 psscale -Dx8.5c/3c/15c/0.5ch -Csurface2.cpt -B500:$TITLE:/:Elevation(m): -O >> $FIGURE.ps
gmt6 psconvert -Tf $FIGURE.ps

Sorry. Forgot the data.
Data-FP-Driver-100-NoHDR.csv.zip (61.8 KB)

Also, here is the R code. fp0 is the same point data. HI_L0_26904 is the basemap data.

output_pdf = paste(“Figure-FP-Driver-100.pdf”, sep=“”)
pdf(file=paste(FIGURE_HOME,‘/’,output_pdf,sep=“”),height=20,width=20)
p1 = ggplot() +
geom_sf(data=HI_L0_26904, aes(geometry=geometry, fill=NAME)) +
coord_sf(datum = sf::st_crs(26904), crs = st_crs(26904),
xlim = c(735500, 765000), ylim = c(2300000, 2329000)) + # Maui
geom_line(data = fp0, aes(x = x, y = y)) +
theme(legend.position=‘none’) +
guides(color = guide_legend(override.aes = list(size = 5))) +
theme(axis.text.x = element_text(angle = 10, vjust = 1.0, hjust=1, size=18),
axis.text.y = element_text(angle = 0, vjust = 1.0, hjust=1, size=18),
axis.title=element_text(size=24,face=“bold”)) +
theme(strip.text = element_text(size = 16, color = “black”, face=“bold”))
invisible(print(p1))
dev.off()

Hey @hellyj,

Thanks for posting all your codes and data :slightly_smiling_face: !

For plotting lines, we have to use -W. -G is (mainly) for filling symbols or polygons.
So can you please try replacing -Gblack with -Wblack? Actually, without giving either -G or -W, GMT should plot lines connecting the data points by default.

All fine, as expected

julia> D = gmtread("Data-FP-Driver-100-NoHDR.csv");
julia> viz(D, Vd=1)
        psxy  -JX15c/10c -Baf -BWSen -R738800/751200/2300000/2329000 -P -K > c:\TMP/GMTjl_j.ps