Both R and Stata are programs with strong data visualization and analysis capabilities. However, Stata’s capabilities as a data visualization program are sometimes under-rated. The intent of the post is to show that Stata can often perform the same graphing task as R, with much simpler, and much more intuitive, command syntax.
This post uses simulated social service agency data clients. In each program, I am going to graph mental health of clients (at Time 2) by program.
Stata
Code
import delimited "clients.csv", encoding(ISO-8859-2) clear// import datagraphbar mental_health_t2, /// bar graph of mean outcomeover(program, gap(10)) /// over programscheme(michigan) /// michigan graph schemeasyvars // bars that have colorquietlygraphexport mybarStata.png, width(2000) replace
(8 vars, 491 obs)
R
Code
library(readr) # library to import dataclients <-read_csv("clients.csv") # import datalibrary(ggplot2)library(michigancolors)ggplot(clients, # the data that I am usingaes(x = program, # 'aesthetic' includes xy = mental_health_T2, # and yfill = program)) +# and fill by programstat_summary(fun = mean, # summarizing y geom ="bar") +# with barsscale_fill_manual(values =michigancolors()) +# UM colorstheme_minimal() # minimal theme