
Often, you may add an option referring to the colours used to fill bars or boxes. The width, or thickness, of the line may be changed via option lwidth, such as inĪpart from some keywords that are available (such as medthin, vthin, or thick ), you can use numbers, as in lwidth(*1.2), which will multiply the default width by a factor of 1.2, or in lwidth(1.2), with the value in parentheses difficult to interpret in substantial terms (it refers to a percentage of the width or height of the graph, whichever is smaller - but to translate this into line width is not easy). (dot = short dash) and # (= small amount of blank space). You may combine elements _ (underscore = long dash), - (hyphen = medium dash). Line sales1 sales2 year, lpattern("_-." "_#") You may also create your own line pattern with the help of a "formula", such as in The last option is just in case you wish to draw an invisible line for some reason or other. Other pattern styles are dot, dash_dot, shortdash, shortdash_dot, longdash, longdash_dot or blank. With the first line being drawn as a solid line and the second as a dashed line. Line sales1 sales2 year, lpattern(solid dash) The pattern of the line may be changed via option lpattern, such as in You may also wish to change the thickness of the line. In a line chart, you may distinguish different lines by colour or pattern.

Of course, I could manually determine this value for the histogram (as I did in this example), but I plan to create a set of these graphs via a loop, such that there are a dozen or so panels. The corresponding lines would instead be: text(1 `median' `"median = $`=string(`median',"%6.2f")'"', /// Instead of "0.08" which gets my text into the correct location, I would like to use "1", as this is the maximum value of the second y-axis. This is the reason I used the second y-axis in the first place. This produces the desired graph (for the most part*):Īt issue is that I do not know the height of the histogram beforehand. Scatteri 0 `median' 1 `median', recast(line) yaxis(2) /// Twoway hist mpg, start(10) width(5) || ///

Here is an example of my issue: sysuse auto However, I cannot seem to add text to this line using the second y-axis coordinates (it instead uses the first y-axis coordinates, even though the object it is labeling is on the second y-axis). To fix this, I am using scatteri with coordinates.īecause I do not know the height of the histogram beforehand, I set the scatteri plot to use a separate y-axis, which I have hidden.

I cannot use xline() because the line falls behind the histogram, rather than on top of it.

I have a plot of a histogram, to which I would like to add the median.
