use "https://github.com/agrogan1/multilevel/raw/master/mlm-R2-gutten/gutten.dta", clear
Introduction 🌲
There is sometimes a debate–shall we say–about whether Stata can make beautiful graphs, particularly in comparison to using ggplot
in R. Below, I try to use as many of Stata’s options as I can to make a beautiful graph. I believe that this Stata graph comes close to being as beautiful of a graph as would be made by ggplot
.
I use green and gold since they are common colors for forestry and park signage.
Data Source 🌲
The data used in this example are derived from the R package Functions and Datasets for “Forest Analytics with R”.
According to the documentation, the source of these data are: “von Guttenberg’s Norway spruce (Picea abies [L.] Karst) tree measurement data.”
The documentation goes on to further note that:
“The data are measures from 107 trees. The trees were selected as being of average size from healthy and well stocked stands in the Alps.”
A Simple Graph 🌲
The default graphing scheme in Stata 18 is much improved over previous versions, and the below graph may be very good for many purposes.
use gutten.dta
twoway (scatter height age_base) (lowess height age_base)
graph export gutten0.svg, width(2000) replace
graph export gutten0.png, width(2000) replace
A Beautiful Graph 🌲
Below please find an admittedly complicated graph command. Note, however, that the graph builds upon basic ideas that we want a twoway
graph, with a scatter
plot and a lowess
smoother. Everything else is just an option to improve the appearance of the graph.
I make extensive use of the ///
notation which allows me to spread the graph along multiple lines.
use gutten.dta
twoway /// two way graph
scatter height age_base, /// scatterplot
(dkgreen%25) msymbol(circle) msize(large)) /// dark green transparent markers
mcolor(/// median spline
(mspline height age_base, gold) lwidth(thick)), /// gold line
lcolor(title("Tree Height by Tree Age") /// title
xtitle("Tree Age") /// title for x axis
ytitle("Tree Height") /// title for y axis
caption("Gutten Tree Data") /// caption
legend(order(1 "trees" 2 "median spline") position(6) rows(1)) /// better labels and format for legend
// better aspect ratio
aspectratio(.5)
graph export gutten.png, width(2000) replace
graph export gutten.svg, width(2000) replace