DATA Step, Macro, Functions and more

Line Chart for monthly data

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

Line Chart for monthly data

[ Edited ]

Dear All,

 

Can you please help me to draw a nice clear chart using four variables on yaxis (SMB HML RM RF) and date on xaxis? I need a line chart for almost 1000 months. I tried and teh oen I got does not seem clear. Please find the sampel data for the line chart, its only around 59 observations in it.

data have;
infile cards truncover;
input date : yymmn6. SMB HML RM RF ;
format Date yymmn6.;
cards;
192607 2.96 -2.30 -2.87 0.22
192608 2.64 -1.40 4.19 0.25
192609 0.36 -1.32 0.01 0.23
192610 -3.24 0.04 0.51 0.32
192611 2.53 -0.20 -0.35 0.31
192612 2.62 -0.04 -0.02 0.28
192701 -0.06 -0.56 4.83 0.25
192702 4.18 -0.10 3.17 0.26
192703 0.13 -1.60 -2.67 0.30
192704 0.46 0.43 0.60 0.25
192705 5.44 1.41 4.93 0.30
192706 -2.34 0.47 -1.53 0.26
192707 7.26 -3.23 -1.16 0.30
192708 1.97 -0.72 -3.69 0.28
192709 4.76 -3.57 -0.71 0.21
192710 -4.31 2.13 -4.33 0.25
192711 6.58 2.76 -0.31 0.21
192712 2.09 0.93 -1.06 0.22
192801 -0.68 4.25 -0.72 0.25
192802 -1.70 -2.03 -0.69 0.33
192803 8.81 -0.26 -1.20 0.29
192804 4.23 3.82 3.67 0.22
192805 1.52 2.98 -3.46 0.32
192806 -4.85 -3.50 -0.06 0.31
192807 0.62 -1.35 -0.47 0.32
192808 6.68 -2.07 -2.11 0.32
192809 2.88 2.18 0.76 0.27
192810 1.33 2.27 -2.26 0.41
192811 11.81 -1.81 2.80 0.38
192812 0.36 -0.85 -0.60 0.06
192901 4.66 -3.55 -1.21 0.34
192902 -0.34 -0.39 1.68 0.36
192903 -0.89 -4.78 1.56 0.34
192904 1.43 -0.99 0.61 0.36
192905 -6.39 -5.46 -1.57 0.44
192906 9.70 -2.17 -2.76 0.52
192907 4.46 -3.87 2.67 0.33
192908 8.18 -9.51 0.07 0.40
192909 -5.47 1.17 -0.63 0.35
192910 -20.12 -4.08 7.85 0.46
192911 -12.74 -1.91 5.33 0.37
192912 1.33 -4.20 -0.59 0.37
193001 5.61 3.58 -1.01 0.14
193002 2.50 0.12 0.39 0.30
193003 7.10 3.44 0.15 0.35
193004 -2.06 -0.17 -0.84 0.21
193005 -1.66 -2.04 -0.63 0.26
193006 -16.27 -3.22 2.00 0.27
193007 4.12 -0.37 -1.56 0.20
193008 0.30 -2.22 -0.78 0.09
193009 -12.75 -2.22 -5.27 0.22
193010 -8.78 -0.10 -1.35 0.09
193011 -3.04 2.21 -3.53 0.13
193012 -7.83 -4.68 -5.39 0.14
193101 6.24 3.81 7.21 0.15
193102 10.88 3.39 1.60 0.04
193103 -6.43 3.07 -3.65 0.13
193104 -9.98 -4.61 -3.92 0.08
193105 -13.24 5.16 -6.57 0.09
run;

Thanks a lot for reading it.

 

Best,

 

MAC


Accepted Solutions
Solution
‎02-05-2017 12:48 AM
Occasional Contributor
Posts: 9

Re: Line Chart for monthly data

Hi, I'm not sure if you tried PROC GPLOT and were satisfied by the line plot exported. A sample code is as follows.

 

/* Define the title of the plot */
title1 "Line Plot";

/* Define the axis of the plot */
axis1 order = (-30 to 20 by 5) label = (a=90 'Y axis') minor=none;
axis2 label=('Date') minor = none;

/* Define the symbol characteristics */
symbol1 interpol=join color=blue line = 1 height=14pt font='Arial';                                                          
symbol2 interpol=join color=red  line = 3 height=14pt font='Arial';                                                       
symbol3 interpol=join color=green line = 8 height=14pt font='Arial';                                                         
symbol4 interpol=join color=black line = 42 height=14pt font='Arial';

/* Add the legend */
legend1 label = (' ') frame; 

/* save the plot in a pdf file */
ods pdf file = "&path\plot1.pdf";

proc gplot data = have;
plot (SMB HML RM RF)*date / vaxis = axis1 haxis=axis2 overlay legend = legend1;
format date yymon7.;
run;

ods pdf close;

gplot16.png

View solution in original post


All Replies
Solution
‎02-05-2017 12:48 AM
Occasional Contributor
Posts: 9

Re: Line Chart for monthly data

Hi, I'm not sure if you tried PROC GPLOT and were satisfied by the line plot exported. A sample code is as follows.

 

/* Define the title of the plot */
title1 "Line Plot";

/* Define the axis of the plot */
axis1 order = (-30 to 20 by 5) label = (a=90 'Y axis') minor=none;
axis2 label=('Date') minor = none;

/* Define the symbol characteristics */
symbol1 interpol=join color=blue line = 1 height=14pt font='Arial';                                                          
symbol2 interpol=join color=red  line = 3 height=14pt font='Arial';                                                       
symbol3 interpol=join color=green line = 8 height=14pt font='Arial';                                                         
symbol4 interpol=join color=black line = 42 height=14pt font='Arial';

/* Add the legend */
legend1 label = (' ') frame; 

/* save the plot in a pdf file */
ods pdf file = "&path\plot1.pdf";

proc gplot data = have;
plot (SMB HML RM RF)*date / vaxis = axis1 haxis=axis2 overlay legend = legend1;
format date yymon7.;
run;

ods pdf close;

gplot16.png

Contributor
Posts: 63

Re: Line Chart for monthly data

Thanks for it. But I am using around 1100 observations and its not that clear to view it. Furthermore, it leaves some pace on left and right side f (inside) the graph,which makes it even smaller.
Super User
Posts: 11,343

Re: Line Chart for monthly data


cheema wrote:
Thanks for it. But I am using around 1100 observations and its not that clear to view it. Furthermore, it leaves some pace on left and right side f (inside) the graph,which makes it even smaller.

You should clarify how "its not that clear to view".  is the issue that your Y values are so close together that you cannot see much difference, which can happen if one series has a significantly different range. If tha is the case almost anything that overlays all 4 series with have a similar issue. Or is that your lines are thick enough, the wrong color or something else?

 

The horizontal axis by default will round you values to pick a "nice" left and right boundary which may have been multiples of 1000 or 5000 days or so. With GPLOT you would use an AXIS statement with the ORDER option to specify the values to display as tick marks which would also set the values of the left and right display as @YiqunDai with the Y axis.

Contributor
Posts: 63

Re: Line Chart for monthly data

Hi ballardw,

 

Thanks for your reply. Yes, y values are quite closeto eachother which makes it difficult to see any specific difference. IF I reduce the observations then its easy to see any difference but the problem is that I need to provide it for the full sample. I will appreciate if you cna help me with it.

 

Thansk in advance for your help.

 

Best,

 

Cheema

Occasional Contributor
Posts: 9

Re: Line Chart for monthly data

What about using goptions to set the size of the graph, like

 

goptions hsize = 80 vsize = 4;

 

Contributor
Posts: 63

Re: Line Chart for monthly data

Thanks, thats fine. Can you please help me with one more thing about this graph, I want to make the black color for teh grapgh.

 

Best,

 

MAC

Occasional Contributor
Posts: 9

Re: Line Chart for monthly data

You mean you want the colors of all lines to be black? Just set the colors in "symbol", for example

 

symbol1 interpol=join color=black line = 1 height=14pt font='Arial';

 

 

Contributor
Posts: 63

Re: Line Chart for monthly data

Sorry, I want background color in black. The display color in black.
Occasional Contributor
Posts: 9

Re: Line Chart for monthly data

You could set the background color in goptions using cback option like

goptions cback = black;

But I think you may also want to set the color of the graph frame, using cframe option in proc gplot, like

proc gplot data = have;
plot (SMB HML RM RF)*date / cframe = black;
run;

If you want let the color of all text and axis be white, use ctext option in goptions and color option in axis, like

goptions cback = black ctext = white;
axis1 color = white;

Hope it helps.

Contributor
Posts: 63

Re: Line Chart for monthly data

Thanks for it.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 204 views
  • 5 likes
  • 3 in conversation