Coder Social home page Coder Social logo

stata-marimekko's Introduction

marimekko-1

StataMin issues license Stars version release


Installation | Syntax | Examples | Feedback | Change log


marimekko v1.1

(02 Dec 2023)

This package provides the ability to draw Marimekko graphs in Stata.

Installation

The package can be installed via SSC or GitHub (the beta is on GitHub only). The GitHub version, might be more recent due to bug fixes, feature updates etc, and may contain syntax improvements and changes in default values. See version numbers below. Eventually the GitHub version is published on SSC.

Install the package as follows:

SSC (v1.1):

ssc install marimekko, replace

or directly from GitHub (v1.1):

net install marimekko, from("https://raw.githubusercontent.com/asjadnaqvi/stata-marimekko/main/installation/") replace

If you want to make a clean figure, then it is advisable to load a clean scheme. These are several available and I personally use the following:

ssc install schemepack, replace
set scheme white_tableau  

I also prefer narrow fonts in figures with long labels. You can change this as follows:

graph set window fontface "Arial Narrow"

Syntax

The syntax for the latest version is as follows:

marikmekko y x [if] [in], label(varname) [ sort(varname) reverse colorp(str) colorn(str)
                lcolor(str) lwidth(num) mlabsize(num) mlabangle(num) mlabgap(num)
                mlabcolor(num) xline(num) yline(num) xlabel(str) xtitle(str) ytitle(str)           
                title(str) subtitle(str) note(str) ysize(num) xsize(num) scheme(str)
                ]

See the help file help marimekko for details.

The basic use is as follows:

marimekko y x, label(variable)

The y and x variables need to be unique across the label() variable. If not, then the program will throw a warning and average the values across the label() variable. In summary, the data should be prepared in advance for the graph.

Examples

Set up the data:

clear
set scheme white_tableau
graph set window fontface "Arial Narrow"

use "https://github.com/asjadnaqvi/stata-marimekko/blob/main/data/demo_r_pjangrp3_pop_change.dta?raw=true", clear

drop NUTS_ID

replace pop = pop / 1000000

ren xvar regions


lab de regions 	1 "Berlin" 2 "Hamburg" 3 "Bayern" 4 "Brandenburg" 5 "Baden-Württemberg" 6 "Hessen" 7 "Schleswig-Holstein" 8 "Rheinland-Pfalz" 9 "Niedersachsen" ///
				10 "Bremen" 11 "Nordrhein-Westfalen" 12 "Mecklenburg-Vorpommern" 13 "Sachsen" 14 "Saarland" 15 "Thüringen" 16 "Sachsen-Anhalt", replace

lab val regions regions

Examples

marimekko change pop, label(regions)

marimekko change pop, label(regions) sort(change) reverse	

marimekko change pop, label(regions) sort(pop) 	

marimekko change pop, label(regions) sort(pop) reverse	

Sort by names:

decode regions, gen(names)

marimekko change pop, label(names) sort(names)	

marimekko change pop, label(regions) sort(change) ylabel(-4(1)4) ytitle("% change in population") xtitle("Population (m)") 

marimekko change pop, label(regions) ylabel(-4(1)4) ytitle("% change in population") xtitle("Population (m)") colorp(green) colorn(purple)

marimekko change pop, label(regions) ///
	colorp(green) colorn(purple) lc(black) lw(0.2) ///
	ylabel(-4(1)4) ytitle("% change in population") xtitle("Population (m)") 

marimekko change pop, label(regions) ///
	colorp(yellow) colorn(lime) lc(black) lw(0.2) mlabs(2) mlaba(45) mlabg(0.1) mlabc(blue) ///
	ylabel(-4(1)4) ytitle("% change in population") xtitle("Population (m)") 

colorpalette w3, nograph	
	
marimekko change pop, label(regions) ///
	colorp("`r(p2)'%50") colorn("`r(p7)'%50") lc(black) lw(0.2) mlabs(2) mlaba(45) mlabg(0.1) mlabc(blue) ///
	ylabel(-4(1)4) ytitle("% change in population") xtitle("Population (m)") ///
	xsize(2) ysize(1)

marimekko change pop, label(regions) ///
	 colorp("%50") colorn("%50") lc(black) lw(0.2) mlabs(2) mlaba(45) mlabg(0.1) mlabc(blue) ///
	ylabel(-4(1)4) ytitle("% change in population") xtitle("Population (m)") yline(1) ///
	xsize(2) ysize(1)

Acknowlegments

The package was inspired by Ansgar Wolsing's Twitter post, and Maarten Lambrechts's Twitter post.

Additionally, there is a lack of general-purpose Stata package for Marimekko charts. I have also discussed this in my article on Mosaic plots on the Stata Guide on Medium.

Feedback

Please open an issue to report errors, feature enhancements, and/or other requests.

Change log

v1.1 (02 Dec 2023)

  • Additional options, such as yline(), xline() added.
  • Code cleanup.

v1.0 (28 Jun 2022)

  • Beta version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.