Announcement

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

  • Graphic legend includes empty categories?

    Greetings!
    Is there a way to force a pie graph legend to include categories that are empty?
    For example, each category below is listed with the number of associated observations:
    cat1 4
    cat2 22
    cat3 21
    cat4 0

    I want cat4 to still appear in the legend even though it is empty.
    Thanks in advance!

  • #2
    I got as far as showing an extra line in the legend() -- and how to do that is explicit in the help.

    I failed to get another colour shown.

    Code:
    clear
    input category freq
    1 4
    2 22
    3 21
    4 0
    end
    
    graph pie [fw=freq] , over(category) legend(order(1 2 3 - "pies: a bad idea")) ///
    pie(4, color(magenta))
    EDIT: The trick seems to be a slice so thin it won't be plotted, but you'll still see a legend entry.

    clear
    input category freq
    1 4
    2 22
    3 21
    4 1e-6
    end

    graph pie [aw=freq] , over(category) legend(order(1 2 3 4 "(not present)")) ///
    pie(4, color(magenta))
    Last edited by Nick Cox; 11 Dec 2018, 05:03.

    Comment

    Working...
    X