concept distribution in category R

This is an excerpt from Manning's book R in Action, Third Edition.
To get a feel for the interface, let’s work through a simple, contrived example. Say that you’re studying physical development and you’ve collected the ages and weights of 10 infants in their first year of life (see table 1.1). You’re interested in the distribution of the weights and their relationship to age.
Figure 6.12. Pie charts displaying the distribution of car classes by year
![]()
Between 1999 and 2008, the distribution of car classes appears to have remained rather constant. The ggpie package can create more complex and customized pie charts. See the documentation (http://rkabacoff.github.io/ggpie) for details.
Histograms display the distribution of a continuous variable by dividing the range of scores into a specified number of bins on the x-axis and displaying the frequency of scores in each bin on the y-axis. You can create histograms using
ggplot(data, aes(x = contvar)) + geom_histogram()where data is a data frame and contvar is a continuous variable. Using the mpg data set in the ggplot package, we'll examine the distribution of city miles per gallon (cty) for 117 automobile configurations in 2008. Four variations of a histogram are created in lisiting 6.8 and the results graphs are presented in figure 6.15.
Violin plots are basically kernel density plots superimposed in a mirror-image fashion over box plots. The middle lines are the medians, the black boxes range from the lower to the upper quartile, and the thin black lines represent the whiskers. Dots are outliers. The outer shape provides the kernel density plot. Here we can see that the distribution of gas mileage for 8-cylinder cars may be bimodal – a fact that is obscured by using box plots alone. Violin plots haven’t really caught on yet. Again, this may be due to a lack of easily accessible software; time will tell.

This is an excerpt from Manning's book Exploring Data with R.
In terms of plot quality, there’s an awful lot of overplotting. Not only that, but many of the movies’ gross earnings are in the same narrow region while some very high earners pushed the y axis upper limit far above this narrow band. A common strategy for alleviating this is to redefine a plot scale to suit the distribution of data. In this case, we’ll transform the y-axis scale to a log scale. First, let’s transform the data by applying the same filtering operation as before and by transforming the year variable to a factor (where the order of levels is descending by year). In Listing 11.9, we obtain the imdb_filtered dataset.
Listing 11.18. A box plot with jittered data points can show us the quantity and distribution of ratings along with the summary statistics
```{r pitchfork_boxplot_points} pitchfork %>% mutate(year = factor(year)) %>% ggplot(aes(x = year, y = score)) + geom_boxplot(outlier.shape = NA, color = "steelblue") + geom_point(position = "jitter", color = "purple", size = 0.2, alpha = 0.25) ```
Listing 11.27. The nycweather dataset is a natural fit for a ridgeline plot, where temperature distibutions are compared by month in 2010
```{r nycweather_ggridges} nycweather %>% filter(!is.na(temp)) %>% mutate( month = lubridate::month(time, label = TRUE, abbr = FALSE), tempf = (temp * 9/5) + 32 ) %>% ggplot(aes(x = tempf, y = month, fill = stat(x))) + geom_density_ridges_gradient( scale = 2, rel_min_height = 0.01, color = "gray50", show.legend = FALSE ) + scale_fill_viridis_c(option = "E") + scale_x_continuous(breaks = seq(10, 100, 10)) + labs( title = "Distributions of Air Temperatures in New York City by Month", subtitle = "Uses nearly 13,000 temperature observations from 2010\n", caption = "Data source: the nycweather dataset from the edr package.", x = "Temperature, ºF", y = NULL ) + theme_ridges() + theme( plot.title.position = "plot", plot.caption.position = "plot", axis.text = element_text(size = 10) ) ```Figure 11.19. A ridgeline plot based on the nycweather dataset.
![]()
The ridgeline plot of Figure 11.19 clearly conveys the distributions of temperatures for each month of 2010. The gradient used in each fill is pleasing to the eye and is highly interpretable. The other comparable plot that uses this data (the Cleveland dot plot in Figure 11.4) has much less information than this plot contains, and the ridgeline variation simply presents so much better.

This is an excerpt from Manning's book Machine Learning with R, the tidyverse, and mlr.
When we measure a variable, it’s often desirable to examine the range of values taken on by the variable. We can do this, for example, using a histogram, where we plot the possible values of our variable against the frequency with which we observed each of them. The shape we get from plotting such a histogram represents the distribution of our variable and tells us information such as where our variable is centered, how dispersed it is, whether its values are symmetrically distributed around its center, and how many peaks it has.
We can summarize distributions of variables using a variety of statistics, such as those that summarize the central tendency of the distribution, those that summarize the dispersion, and those that summarize the shape and symmetry. Visually inspecting the distributions of our variables is important, however, to help us decide the best way to handle different variables.
In chapter 18, I showed you the DBSCAN and OPTICS algorithms, and how they find clusters by learning regions of high and low density in the feature space. Mixture model clustering takes yet another approach to identify clusters. A mixture model is any model that describes a dataset by combining a mix of two or more probability distributions. In the context of clustering, mixture models help us to identify clusters by fitting a finite number of probability distributions to the data and iteratively modifying the parameters of those distributions until they best fit the underlying data. Cases are then assigned to the cluster of the distribution under which they are most likely. The most common form of mixture modeling is Gaussian mixture modeling, which fits Gaussian (or normal) distributions to the data.

This is an excerpt from Manning's book Practical Data Science with R, Second Edition.
summary()— Provides a summary of almost any R object. summary(uciCar) shows us a lot about the distribution of the UCI car data.
A distribution is a description of likelihoods of possible values in a set of data. For example, it could be the set of plausible heights of an adult, American, 18-year-old male. For a simple numeric value, the distribution is defined thus: for a value b, the distribution is the probability of seeing a value x, with x <= b. This is called the cumulative distribution function (CDF).
We can often summarize a set of possible outcomes by naming a distribution, and some summary statistics. For example, we can say that if we flip a fair coin 10 times, the number of heads we observe should be binomially distributed (defined in section B.5.7) with an expected mean of 5 heads. In all cases, we are concerned with how values are generated, and getting a bit more detail beyond just a characterization of mean and standard deviation, such as getting the name and shape of the distribution.
Listing B.2. Plotting an empirical normal density
library(ggplot2) # draw 1000 points from a normal with mean 0, sd 1 u <- rnorm(1000) # plot the distribution of points, # compared to normal curve as computed by dnorm() (dashed line) ggplot(data.frame(x=u), aes(x=x)) + geom_density() + geom_line(data=data.frame(x=x,y=f), aes(x=x,y=y), linetype=2)As you can see in figure B.2, the empirical distribution of the points produced by rnorm(1000) is quite close to the theoretical normal. Distributions observed from finite datasets can never exactly match theoretical continuous distributions like the normal; and, as with all things statistical, there is a well-defined distribution for how far off you expect to be for a given sample size.
Figure B.2. The empirical distribution of points drawn from a normal with mean 0 and standard deviation 1. The dotted line represents the theoretical normal distribution.
![]()
The function pnorm(x, mean = m, sd = s) is what R calls the normal probability function, otherwise called the normal cumulative distribution function: it returns the probability of observing a data point of value less than x from a normal with mean m and standard deviation s. In other words, it’s the area under the distribution curve that falls to the left of x (recall that a distribution has unit area under the curve). This is shown in the listing B.3.

This is an excerpt from Manning's book R in Action, Second Edition: Data analysis and graphics with R.
To get a feel for the interface, let’s work through a simple, contrived example. Say that you’re studying physical development and you’ve collected the ages and weights of 10 infants in their first year of life (see table 1.1). You’re interested in the distribution of the weights and their relationship to age.
You can see in figure 6.12 that there’s a good separation of groups based on gas mileage. You can also see that the distribution of mpg for six-cylinder cars is more symmetrical than for the other two car types. Cars with four cylinders show the greatest spread (and positive skew) of mpg scores, when compared with six- and eight-cylinder cars. There’s also an outlier in the eight-cylinder group.
In the previous section, you saw a kernel density plot superimposed on a histogram. Technically, kernel density estimation is a nonparametric method for estimating the probability density function of a random variable. Although the mathematics are beyond the scope of this text, in general, kernel density plots can be an effective way to view the distribution of a continuous variable. The format for a density plot (that’s not being superimposed on another graph) is