Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Contour plot error: contour command displays data that does not exist!

    I have found that the contour command displays data that does not exist.

    In my code, bug_in_contour_demo.do, I use the data demo_of_contour_error.dta to produce the (prettier pdf version of) the graph below. But, the two vertical lines above most of the data actually should be points!
    Has anyone else had this problem?
    Click image for larger version

Name:	demo_contour_error_small.png
Views:	1
Size:	32.6 KB
ID:	1706311

  • #2
    twoway contour draws rectangles based on grids defined by x and y values around those two points. the top "line" is the rectangle filling the upper half of the 32 to 17 based on point (57, 32), and the bottom "line" is the rectangle filling the lower half of the 32 to 17 based on point (0, 17).

    I would suggest give Ben Jann's heatplot a try to see if that is closer to what you want. You need:

    Code:
    ssc install palettes
    ssc install colrspace
    ssc install heatplot
    Then:

    Code:
    heatplot freq  grid_river grid_aoc

    Comment


    • #3
      Thanks. Not sure I understand why it's constructing the grid without using the same rectangle everywhere. Is there a way to control that behavior?

      You are right that I'm using twoway contour for a heat map. I'm doing that on purpose because I need a twoway plot type for the rest of what I'm doing. This was a simplified example meant to clearly display what I consider to be strange behavior of the contour plot, but it doesn't include the rest of the stuff I'm putting on this graph.

      I'll try to see if heatplot can achieve my goals despite not being a twoway plot type. Thanks!

      Comment


      • #4
        > Is there a way to control that behavior?

        Unfortunatelly not now but I will think about it. The grid is constructed from the data and the rectangles around those two points are not constructed differently from other places. They stand out simply because the data points there are sparse.

        If heatplot does not work for your situation, please send an email to techsupport at tech-support@stata.com and I will see if we can add an option to twoway contour.

        Comment


        • #5
          Hi Hua,
          Thanks for your help. I think I'm fine now, though.
          I figured out how to make the grid points the same units across the entire grid, by adding some "ghost observations" with missing values of the z variable. Twoway contour works fine with the ghost observations.
          There's a heat map style graph and a more interpolated style graph that can be produced with twoway contour. See attached.
          Alecia
          Attached Files

          Comment


          • #6
            Glad to hear that you found a solution.

            Hua.

            Comment

            Working...
            X