Aligning contour line with contour filled plot irregular grid polar plot (semi circle)

前端 未结 1 1377
伪装坚强ぢ
伪装坚强ぢ 2021-01-07 14:41

I see several people have answered the question for plotting with an irregular grid. I\'m having trouble getting the contour lines to line up with the filled contours. Als

相关标签:
1条回答
  • 2021-01-07 14:59

    The contours and colours do not align because filled.contour produces two plots (legend and contour). After plotting, these coordinate systems are lost. (?filled.contour). This can be solved by adding the relevant commands to the plot.axes argument. Semi-circles can be drawn with draw.arc from the plotrix package, spokes with segments. The zone within a minimum radius can be covered by white segments to represent no data.

    # min distance of contours lines from center
    min_dist=5
    
    # position of spokes (degrees)
    spk = seq(0,180,30)
    
    filled.contour(x = fld$x,
                   y = fld$y,
                   z = fld$z,
                   color.palette = colorRampPalette(c("white", "blue")),
                   xlab = "",
                   ylab = "",
                   main = "Max",
                   key.title = title(main = "Value", cex.main = 1),
                   asp=1, xlim=c(0,40), ylim=c(-30,30),   frame.plot=F,
                   plot.axes = {contour(fld$x, fld$y, fld$z , add=T, levels = seq(0,max(fld$z, na.rm=T),30), drawlabels=F, col=2);
                                # semi circles
                                draw.arc(x=0,y=0,radius = (1:3)*10, deg1=90, deg2=-90, col='grey');
                                # cover zone within minimum radius with (draw many closely spaced white lines
                                segments(x0 = 0, y0 = 0, x1 = sin((0:180)*pi/180)*min_dist, y1 = cos((0:180)*pi/180)*min_dist, col='white');
                                # spokes with labels
                                segments(x0 = 0, y0 = 0, x1 = sin(spk*pi/180)*30, y1 = cos(spk*pi/180)*30, col='grey');
                                text(x = sin(spk*pi/180)*30, y=cos(spk*pi/180)*30, labels = spk, pos=4, cex=0.6, xpd=NA)
                                # data points
                                points(x,y, pch=16, cex=0.6);
                                # x axis
                                axis(1);
                                # modified y axis
                                axis(2, at = axisTicks(range(y), log=F), labels = abs(axisTicks(range(y), log=F)), pos = 0);
                   }
    )
    

    enter image description here

    0 讨论(0)
提交回复
热议问题