[TIL] 16-Feb-2020
ggplot2, fullwidth class, utility classes kramdown, R primer site, complete.cases()
ggplot2 is a graphing package in R. The basic workflow of plotting is by using layers.ggplot(data = mpg)
sets up an empty graph figure and gives it access to data inside mpg. geom_point(mapping = aes(x = cty, y = class))
is then a separate layer that puts points in the figure/graph and maps the 2 properties of those points x and y to the variables cty and class which are both found in mpg. The amazing thing with ggplot is that we can map different attributes of our aesthetic to different variables in our mpg dataframe. Our aesthetic here is basically a point. we have mapped the x and y coordinates of that point already but points can also have other attributes like shape, color, size, alpha (which means opacity) etc. Any of these attributes could be mapped to variables in mpg like so: geom_point(mapping = aes(x = cty, y = class, color = hwy, shape = displ))
. If we didnt want to map an attribute to a variable and just wanted to Set an attribute like fix the color of all points to something then we would set it outside the aes() mapping like geom_point(mapping = aes(x = cty, y = class), color = "red")
. We basically add these layers on top of each other like:
ggplot(data = mpg) +
geom_point(mapping = aes(x = cty, y = class))
A geom is the geometrical object that a plot uses to represent observations. People often describe plots by the type of geom that the plot uses. For example, bar charts use bar geoms, line charts use line geoms, boxplots use boxplot geoms, and so on. Scatterplots break the trend; they use the point geom.
Inorder to display full width content like the above pdf that breaks out of its parent container we use this full-width utility class Which I just threw inside style tags within this markdown file:
.full-width {
left: 50%;
margin-left: -50vw;
margin-right: -50vw;
max-width: 100vw;
position: relative;
right: 50%;
width: 100vw;
}
Also inorder to add classes to blocks within markdown, since we are using kramdown we can add this at the bottom of textblock:
{: text-justify}
Which is just a utility class in minimal-mistakes which justifies the text, for more info read this link.
R studio has a really good set of tutorial primers.
In R if you are only interested in getting those rows which have no na values, i.e the rows that are complete. Then you just use the complete.cases() function on the dataframe which returns a logical vector which you can use to index into your dataframe like so:
good_rows <- complete.cases(mydataframe)
mydataframe_complete_rows <- mydataframe[good_rows]
Linear mixed models for Hierarchical Data, Only know the name and a very hand wavy explanation : Correlations in data due to things like area / school that can basically group our observations into clusters are called Random Effects and they are dealt with by using Linear models with Random Intercept and Random Slope.