I would like to plot a density so that it displays a grayscale going from white on the extreme left part to black in the extreme right part.
My code is as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(log_lag_tot_sales log_lead_tot_sales log_lagged2_tot_sales log_lead2_tot_sales)
. . . .
. 11.57562 . 11.556605
10.6708 11.556605 . 6.168915
11.57562 6.168915 10.6708 1.6467954
11.556605 1.6467954 11.57562 .
6.168915 . 11.556605 .
. 10.74079 . .
14.58203 . . .
. . . .
. 11.118983 . 11.331554
10.865294 11.331554 . 11.343142
11.118983 11.343142 10.865294 11.336972
11.331554 11.336972 11.118983 11.55704
11.343142 11.55704 11.331554 11.473188
11.336972 11.473188 11.343142 11.52564
11.55704 11.52564 11.336972 11.655797
11.473188 11.655797 11.55704 11.63217
11.52564 11.63217 11.473188 11.290495
11.655797 11.290495 11.52564 10.561643
11.63217 10.561643 11.655797 .
11.290495 . 11.63217 .
. 3.34627 . 2.9033904
3.5634015 2.9033904 . 2.662851
3.34627 2.662851 3.5634015 .
2.9033904 . 3.34627 .
. . . .
. 6.938858 . .
12.3347 . . .
. 14.290753 . 14.203842
14.289332 14.203842 . 14.459516
14.290753 14.459516 14.289332 14.51494
14.203842 14.51494 14.290753 14.752728
14.459516 14.752728 14.203842 14.711233
14.51494 14.711233 14.459516 14.565996
14.752728 14.565996 14.51494 12.56849
14.711233 12.56849 14.752728 .57972085
14.565996 .57972085 14.711233 11.687688
12.56849 11.687688 14.565996 11.903893
.57972085 11.903893 12.56849 .
11.687688 . .57972085 .
. 10.056931 . 9.288839
10.000427 9.288839 . 8.336972
10.056931 8.336972 10.000427 8.602725
9.288839 8.602725 10.056931 9.005105
8.336972 9.005105 9.288839 8.550479
8.602725 8.550479 8.336972 8.761358
9.005105 8.761358 8.602725 8.991681
8.550479 8.991681 9.005105 9.026819
8.761358 9.026819 8.550479 8.825924
8.991681 8.825924 8.761358 8.781609
9.026819 8.781609 8.991681 .
8.825924 . 9.026819 .
. . . .
. 8.611331 . 9.3185625
7.614491 9.3185625 . 9.180587
8.611331 9.180587 7.614491 9.650503
9.3185625 9.650503 8.611331 9.102926
9.180587 9.102926 9.3185625 9.308524
9.650503 9.308524 9.180587 9.465543
9.102926 9.465543 9.650503 .
9.308524 . 9.102926 .
. 5.454896 . 5.640154
7.190414 5.640154 . .
5.454896 . 7.190414 .
. .6292556 . 1.1384683
1.6762704 1.1384683 . -.26826787
.6292556 -.26826787 1.6762704 .7881434
1.1384683 .7881434 .6292556 .
-.26826787 . 1.1384683 6.743719
. 5.427053 .7881434 4.817077
6.743719 4.817077 . 4.873231
5.427053 4.873231 6.743719 .
4.817077 . 5.427053 .
. 5.668871 . 5.276427
5.821651 5.276427 . .3716027
5.668871 .3716027 5.821651 .
5.276427 . 5.668871 .
. 10.069922 . 10.24204
10.129775 10.24204 . 9.494603
10.069922 9.494603 10.129775 8.728362
10.24204 8.728362 10.069922 8.757013
9.494603 8.757013 10.24204 8.681924
8.728362 8.681924 9.494603 8.750833
8.757013 8.750833 8.728362 8.979093
8.681924 8.979093 8.757013 8.8749075
8.750833 8.8749075 8.681924 8.915873
8.979093 8.915873 8.750833 8.884404
8.8749075 8.884404 8.979093 .
8.915873 . 8.8749075 .
. 10.20618 . 5.027871
10.34363 5.027871 . 2.919647
10.20618 2.919647 10.34363 .
5.027871 . 10.20618 .
. 5.309826 . 2.843353
5.749509 2.843353 . .
5.309826 . 5.749509 .
. 12.95111 . 13.288822
12.489015 13.288822 . 13.39754
12.95111 13.39754 12.489015 13.32778
13.288822 13.32778 12.95111 13.493407
end
Code:
twoway (kdensity log_lag_tot_sales if recalled_class_two ==1, lcolor(red) lpattern(solid)) (kdensity log_sales if recalled_class_two ==1,lcolor(blue) lwidth(medthin) lpattern(dash)) (kdensity log_lagged2_tot_sales if recalled_class_two ==1, lcolor(green) lwidth(medium) lpattern(longdash_shortdash)), title(Sales (logarithmic scale):) subtitle(density one and two years before the recall) ytitle(Density) xtitle(Logarithm of total sales) legend(order(1 "sales one year before recall" 2 "growth sales current year" 3 "growth sales two years before recall") col(1)) name(grafico1, replace) twoway (kdensity log_lead_tot_sales if recalled_class_two ==1, lcolor(red) lpattern(solid)) (kdensity log_sales if recalled_class_two ==1,lcolor(blue) lwidth(medthin) lpattern(dash)) (kdensity log_lead2_tot_sales if recalled_class_t ==1, lcolor(green) lwidth(medium) lpattern(longdash_shortdash)), title(Sales (logarithmic scale):) subtitle(density one and two years after the recall) ytitle(Density) xtitle(Logarithm of total sales) legend(order(1 "sales one year after recall" 2 "sales current year" 3 "growth sales two years after recall") col(1)) name(grafico2, replace)
Thank you in advance,
Federico
0 Response to Grayscale
Post a Comment