Announcement

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

  • Edit line pattern in graph by code

    Dear Statalisters,

    I want to adjust the line patterns and colors in my graph with the following code:

    lpoly medPY010G PX020 if PB020=="DE", lpattern (dash) lcolor (black) noscatter addplot((lpoly medPY010G PX020 if PB020=="UK", lpattern (solid) lcolor (black)) (lpoly medPY010G PX020 if PB020=="NL", lpattern (dash_dot) lcolor (black)) (lpoly medPY010G PX020 if PB020=="IT", lpattern (shortdash) lcolor (black)) (lpoly medPY010G PX020 if PB020=="IE", lpattern (shortdash_dot) lcolor (black)) (lpoly medPY010G PX020 if PB020=="HU", lpattern (longdash_dot) lcolor (black))) title (test) legend(label(1 "DE") label(2 "UK") label (3 "UK") label (4 "NL") label(5 "IE") label (6 "HU"))

    It works for all lines except the line for the first country "DE". I guess it is probably because I also specified noscatter? But even without that, that line does not change. I have tried various commands like:lpoly medPY010G PX020 if PB020=="DE", noscatter connect(l) lpattern (dash) lcolor (black)

    Unfortunately, I cnanot find a code to change the pattern and color of that one line.
    Does somebody has an idea how that could work?

    Thanks in advance for any help!
    Janina
    Attached Files

  • #2
    Please post following guidelines in Statalist FAQ. Graphs should be shown as .png like this and code should be made readable by using CODE delimiters.

    Code:
    lpoly medPY010G PX020 if PB020=="DE", lpattern (dash) lcolor (black) noscatter
    addplot((lpoly medPY010G PX020 if PB020=="UK", lpattern (solid) lcolor (black))
    (lpoly medPY010G PX020 if PB020=="NL", lpattern (dash_dot) lcolor (black))
    (lpoly medPY010G PX020 if PB020=="IT", lpattern (shortdash) lcolor (black))
    (lpoly medPY010G PX020 if PB020=="IE", lpattern (shortdash_dot) lcolor (black))
    (lpoly medPY010G PX020 if PB020=="HU", lpattern (longdash_dot) lcolor (black)))
    title (test) legend(label(1 "DE") label(2 "UK") label (3 "UK") label (4 "NL") label(5 "IE") label (6 "HU"))
    Click image for larger version

Name:	Graph_LifCycleByCounty.png
Views:	1
Size:	38.4 KB
ID:	1407238



    Elsewhere in computing is the idea of a minimal, complete, verifiable example. We can't test your code because you don't give any of your data but following the principles at https://stackoverflow.com/help/mcve we can agree that

    Code:
    sysuse auto
    lpoly mpg weight, lpattern(dash) lcolor(black) noscatter
    produces a solid pattern. The reason is that -- as documented -- you need lineopts() here.

    Code:
    lpoly mpg weight, lineopts(lpattern(dash) lcolor(black)) noscatter
    Note that the graph command is varying the line pattern but independently of your code. You'll also want to fix the mistake of using UK twice and omitting IT from the legend.

    Moral: It's all in the help.
    Last edited by Nick Cox; 21 Aug 2017, 03:53.

    Comment

    Working...
    X