asjadnaqvi / stata-circlepack

A Stata package for circle packing
MIT License
6 stars 0 forks source link

Custumize circles color #1

Open piumatti opened 2 years ago

piumatti commented 2 years ago

Hello,

Thanks a lot for another great package in Stata! I was wondering if within circlepack it is possible to customize the color of different circles.

Thanks in advance,

Giovanni

asjadnaqvi commented 2 years ago

I can potentially add a second and third color palette options for the layers. I will run some tests and see how it looks.

DanishKhan671 commented 1 year ago

Hi @asjadnaqvi and @piumatti. I hope you are both doing well. I recently made a circlepack graph for one of my projects. After making the graph I also felt the need to custom color the graph so I made a small yet effective program in my do file to create my own palette for custom coloring. I am sharing an example below. Hope this is a valuable addition to the great package that Asjad has made for us.

` /* Author: Danish Naeem Khan

Title:      Custom Coloring Circlepack Graphs

Purpose:    To demonstrate an example on how you can custom color your 
            circlepack graphs by generate a simple program.

Date:       March 11, 2023

Last Edited
Name:       Danish Naeem Khan
Date:       March 11, 2023

Note: This work only demonstrate an example to custom color the circlepack
        graphs created by ## Asjad Naqvi ##. 
        ** Thank you Asjad for sharing such an amazing package with us! **

*/

****************************    Initializing    *************************

clear all
set more off
pause off
mat drop _all

****************************    Set Scheme(s)   *************************
set scheme white_tableau
graph set window fontface "Arial Narrow"

******************************* Load Data   *****************************

global url1 = "https://github.com/asjadnaqvi/stata-circlepack/"
global url2 = "blob/main/data/demo_r_pjangrp3_clean.dta?raw=true"

use "$url1$url2", clear

****************************    Example Demo    *************************

drop year
keep NUTS_ID y_TOT

drop if y_TOT==0

keep if length(NUTS_ID)==5

gen NUTS2 = substr(NUTS_ID, 1, 4)
gen NUTS1 = substr(NUTS_ID, 1, 3)
gen NUTS0 = substr(NUTS_ID, 1, 2)

ren NUTS_ID NUTS3

keep if (NUTS0 == "TR" | NUTS0 == "ES" | NUTS0 == "NL" | NUTS0 == "EL" | NUTS0 == "RO")

* To make a custom palette, place your colors in your desired order in
* this program. First color will be placed on first circle.
* Find more color palettes on Adobe Color (link below) as suggested by
* Asjad Naqvi.
* "https://color.adobe.com/create/color-wheelhttps://color.adobe.com/create/color-wheel"

capture program drop colorpalette_rank1
program colorpalette_rank1
    c_local P 17 168 100, 168 24 24, 168 17 143, 168 168 57, 57 146 168
    c_local I CustomDGreen, CustomCranberry, CustomPurple, CustomOlive, CustomTeal
    end

#delimit ;
circlepack y_TOT, by(NUTS1 NUTS0) format(%15.0fc) 
title("Circle Pack with Default Coloring") noval circle0
;
#delimit cr

* You can use "palette" option in circlepack to set your custom scheme on 
* the graph.

#delimit ;
circlepack y_TOT, by(NUTS1 NUTS0) format(%15.0fc) palette(rank1) 
title("Circle Pack with Custom Coloring") noval circle0
;
#delimit cr

********************************    END ********************************

`

asjadnaqvi commented 1 year ago

That is a great solution!