Announcement

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

  • Changed/changing histogram legend position

    Dear Statalist members,

    Previous to Stata 18 (SE), histogram legends were positioned at 3, now they are positioned at 6 by default. How do I change that position?
    sysuse auto, clear
    version 18
    hist price, by(foreign) kdensity scheme(s2color) // old legend at 6
    hist price, by(foreign) kdensity // new legend at 3
    If I want to use the new default scheme, but move the legend to 6, it does not work:

    hist price, by(foreign) kdensity legend(position(6)) // does not change anything
    It has nothing to do with the legend typically being turned off for histograms. If I explicitly turn it on, I get something that I definitely do not want, i.e., three legends, with the main legend still in the wrong place:
    hist price, by(foreign) kdensity legend(on position(6)) // is not the solution I need
    Do you have any idea how I can move the legend from the right to the bottom, i.e., to its pre-Stata 18 default position?

    Thank you very much for your help!

    Best,
    Tobias

  • #2
    I cannot replicate your problem. For me, on Stata 18, I get the legend at the 6 position with both the following commands:
    Code:
    hist price, by(foreign) kdensity scheme(s2color)
    hist price, by(foreign) kdensity
    That said, if you want the legend at 3, you need to specify that within the -by- option

    Code:
    hist price, by(foreign, legend(pos(3))) kdensity
    See also: help by_option##use_of_legends

    Comment


    • #3
      Oh, I just realised why I wasn't replicating your issue: my default scheme is set to cleanplots while yours is probably the new Stata 18 default, stcolor. I can replicate the legend being at 3 with the stcolor scheme. The core advice remains intact, though. To shift the legend to the 6 position, you should put that option within the -by-.

      Code:
      hist price, by(foreign, legend(pos(6))) kdensity scheme(stcolor)

      Comment


      • #4
        Dear Hemanshu Kumar,

        Thank you so much for your help!

        Best,
        Tobias

        Comment

        Working...
        X