The format %9.1f means "format the number such that it fits in no more than nine total spaces (more than enough) with one digit after the decimal point, following the general rules for floating point numbers" but you don't really need to memorize all that. You can tell Stata how to format the labels by putting a format option inside the blabel option with the format you want. Some of the labels have more significant digits than are useful. This is done by adding the blabel (bar label) option with bar (bar height) in the parentheses: You can fix that, at the price of adding some clutter to your graph, by putting a label on each bar that gives the height of the bar. While this graph makes it easy to see the relationship between the two variables, it's hard to read off the values of the means. You can convert this graph to a horizontal bar graph by changing the command from graph bar to graph hbar: They're especially good if the category names are long. Many people prefer horizontal bar graphs because they better match the eye's natural left-to-right, top-to-bottom reading pattern (western eyes, anyway). Now the relationship is immediately obvious. The variable that defines the categories (in this case, class) goes in an option called over: To make a bar graph of the same information, use the command graph bar followed by the quantitative variable whose means you want to see (in this case, edu). -Ī few seconds spent examining this table will show that mean education increases with subjective class identification. Which gives the following output: SUBJECTIVE |ĬLASS | Summary of HIGHEST YEAR OF SCHOOL In the Descriptive Statistics section, one of the examples was: Mean of a Quantitative Variable Across a Categorical Variable If you plan on applying what you learn directly to your homework, create a similar do file but have it load the data set used for your assignment. Then create a do file called bargraph.do in that folder that loads the GSS sample as described in Doing Your Work Using Do Files. If you plan to carry out the examples in this article, make sure you've downloaded the GSS sample to your U:\SFS folder as described in Managing Stata Files. You can build on what you learn here to create much more complex graphs. Mean of a Quantitative Variable Across a Categorical Variable.In this article we'll discuss two simple bar graphs: This is especially useful for non-technical audiences. In order to avoid repeating code we will use the following function to plot two Bessel functions in R ( J_0(x) and J_2(x)): plotl <- function(.Bar graphs are a very useful tool for presenting summary statistics because the reader can instantly grasp the relationships between the various values. In the following sections we will explain how to customize the most common arguments of the function. Recall that there are even more arguments you can use, but we listed the most common, so type args(legend), ?legend or help(legend) for additional information. Horiz = FALSE # Horizontal (TRUE) or vertical (FALSE) legend Pch, # Add pch symbols to legend lines or boxesīty = "o", # Box type (bty = "n" removes the box)īg = par("bg") # Background color of the legendīox.lwd = par("lwd"), # Legend box line widthīox.lty = par("lty"), # Legend box line typeīox.col = par("fg"), # Legend box line color Legend, # Vector with the name of each groupįill, # Creates boxes in the legend with the specified colorsĬol = par("col"), # Color of lines or symbolsīorder = "black", # Fill box border color The summarized syntax of the function with the most common arguments is described in the following block: legend(x, y, # Coordinates (x also accepts keywords) The legend function allows you to add a legend to a plot in base R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |