I would like to format the background colour on a xtline graph according to the values on the y-axis.
I have a dataset with 50 persons' BMI at two timepoints: baseline (1) and after intervention (2). I want a graph where each of these 50 BMIs are shown from time 1 to time 2, which I have done using xtline. However, my problem is to change the colour of the background according to the BMI, such that a y-value >=40 has a dark gray background, a y-value 35-39.9 has a semi-dark gray background, etc. I can do this via the scatteri recast(area) function, however, I can't manage to combine the scatteri recast(area)-graph with the xtline graph - I thought I could do this using the overlay command, but I get an error: "xtline is not a twoway plot type", so I'm looking for another way to do this.
Below is my code. The scatteri recast(area)-graph works perfectly (on its own), as does the xtline, so the problem is to combine them.
Thank you for your time.
- Sara
I have a dataset with 50 persons' BMI at two timepoints: baseline (1) and after intervention (2). I want a graph where each of these 50 BMIs are shown from time 1 to time 2, which I have done using xtline. However, my problem is to change the colour of the background according to the BMI, such that a y-value >=40 has a dark gray background, a y-value 35-39.9 has a semi-dark gray background, etc. I can do this via the scatteri recast(area) function, however, I can't manage to combine the scatteri recast(area)-graph with the xtline graph - I thought I could do this using the overlay command, but I get an error: "xtline is not a twoway plot type", so I'm looking for another way to do this.
Below is my code. The scatteri recast(area)-graph works perfectly (on its own), as does the xtline, so the problem is to combine them.
Code:
xtset id time xtline egfr, overlay xlabel (1 2) ylabel (14 45) legend(off)
Code:
twoway scatteri 35 1 45 1 45 2 35 2, recast(area) color(gs16%50) || scatteri 30 1 35 1 35 2 30 2, recast(area) color(gs14%50) || scatteri 25 1 29 1 29 2 25 2, recast(area) color(gs12%50) || scatteri 24 1 18.5 1 18.5 2 24 2, recast(area) color(gs10%50) || scatteri 16 1 18.4 1 18.4 2 16 2, recast(area) color(gs8%50) || scatteri 15 1 16 1 16 2 15 2, recast(area) color(gs6%50) xlabel(1 "Pre" 2 "Post") legend(order(1 "Severly obese" 2 "Obese" 3 "Overweight" 4 "Normalweight" 5 "Underweight" 6 "Severe underweight") pos(11)) ytitle(BMI) xtitle("Time")
Thank you for your time.
- Sara
Comment