Dear Statalist,
I am just wondering how to set custom colours (and/or other formatting) for each "segment" that comprises a stacked bar chart. I know these can be manually edited in the graph editor by altering the "object specific properties", however this is tedious to do for multiple instances. I was wondering whether the is a more automated way of doing this?
An example of the type of chart is the following (with what I would like to achieve):

I've tried the following approach in which I generate a variable colour containing the colour in an RGB format, looping through all of the bar segments and then sending this to the bar chart. However this does not work as the colours are changed for all elements belong to each over(y) category.
Is this possible?
For example, in this previous Statalist discussion on customising bar labels, the internal graphing classes/macros were accessed and edited to achieve this. There must be similar objects storing the bar colours for each "rectangle" in the chart, which can be accessed and modified in a similar way.
Thank you in advance for any assistance.
Best wishes,
Alex
I am just wondering how to set custom colours (and/or other formatting) for each "segment" that comprises a stacked bar chart. I know these can be manually edited in the graph editor by altering the "object specific properties", however this is tedious to do for multiple instances. I was wondering whether the is a more automated way of doing this?
An example of the type of chart is the following (with what I would like to achieve):
I've tried the following approach in which I generate a variable colour containing the colour in an RGB format, looping through all of the bar segments and then sending this to the bar chart. However this does not work as the colours are changed for all elements belong to each over(y) category.
Code:
local n = _N local bars = "" forvalues i = 1/92 { local barcol = colour[`i'] local recol = "bar(`i', fcolor(" + `"`barcol'"' + "))" local bars = `"`bars'"' + " " + `"`recol'"' } graph bar x, over(y) stack asyvars over(z) `bars'
For example, in this previous Statalist discussion on customising bar labels, the internal graphing classes/macros were accessed and edited to achieve this. There must be similar objects storing the bar colours for each "rectangle" in the chart, which can be accessed and modified in a similar way.
Thank you in advance for any assistance.
Best wishes,
Alex
Comment