Announcement

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

  • How to plot a scatter graph with just a few dots around a fitted line?

    Hi just wondering how to plot a scatter graph with just a few dots around a fitted line like that in the attachment? I have explored the options of "scatter" but it seems to be not the right command. Thanks a lot! plot.docx

  • #2
    No Word (or Excel) attachments please. We explain that, and why we ask, and what to do instead at https://www.statalist.org/forums/help#stata

    Graphics can be posted here as .png which makes them immediately visible without people having to fire up third-party software they may not even have. What's worse, Word documents can spread malware.

    Comment


    • #3
      While I also did not want to open the attachment, I think this minimal example explains it quite well.


      Code:
      sysuse auto
      twoway scatter mpg weight || lfit mpg weight
      But now assume these are too much points for you.

      I would just plot a random subset, e.g. around 20% of the data. There are many ways for doing this, the short way I usually would do this:

      Code:
      gen identifier = uniform()
      tab identifier if identifier < .2
      
      twoway lfit mpg weight ||  scatter mpg weight if identifier <.2
      Hope that helps.


      Edit: I mean with the if-condition you could also decide to just plot those specific points that you want ...
      Last edited by Gracia Brueckmann; 15 Jul 2020, 08:30.

      Comment


      • #4
        I can't speak for whether #2 answers #1. I know that as a reader, reviewer, listener I would be very puzzled by a graph that capriciously shows some of the data but not all, without a separate rationale.

        Other choices include one or more of

        smaller marker symbols

        less obtrusive marker symbols

        fainter colours for markers.

        Comment


        • #5
          Thanks a lot! Sorry for the inconsideration. It turns out that "binscatter'" will do. Thanks again!

          Comment

          Working...
          X