WEEK 4: More VIsualisations, aesthetics and annotations Flashcards
ggplot2
The ggplot2 package lets you use R code to specify the dataset, geom, and aesthetics of your plot.
aesthetic
a connection or mapping between a visual feature in your plot and a variable in your data.
A geom
Refers to the geometric object used to represent your data.
Facets
With facets, you can create separate plots for all the variables in your dataset.
Label and annote
You can add text like titles, subtitles and captions to communicate the purpose of your plot or highlight important data.
To create a plot
Follow these three steps: start with the ggplot function and choose a dataset to work with, add a geom_function to display your data, map the variables you want to plot in the argument of the aes function.
Aesthetics for points
X,Y Shape, Color, Size, Alpha (transparency)
ggplot2 function
ggplot(data =penguins) + geompoint(mapping = aes(x= length, y = height, color = species))
geom funtions
geom_point
geom_bar
geom_line
If we want to plot a separate line for each elements of our data
add line type to the aes funtion
Ex: ggplot(data =penguins) + geom_point(mapping = aes(x= length, y = height, linetype=species))
Jittering
helps us deal with over-plotting, which happens when the data points in a plot overlap with each other.
Ex: ggplot(data =penguins) + geom_jitter(mapping = aes(x= length, y = height, linetype=species))
bar chat aesthetics function
ggplot (data=diamonds) + geom_bar ( mapping =aes(x=cut, color=cut or fill = cut))
Ggplot2’s smoothing functionality
Is helpful because it adds a smoothing line as another layer to a plot; the smoothing line helps the data to make sense to a casual observer.
Facet functions
Let you display smaller groups or subsets of your data.
To facet your plot by a single variable, use facet underscore wrap.
tidle (~)
To facet your plot by a single variable, use facet underscore wrap.
If your is visual is too busy, for example, if it’s got too many variables or levels within variables, faceting can be a good option.