Visual Analytics Flashcards
(170 cards)
What are geoms?
Visual marks representing data points
Geoms, short for “geometric objects” are the basic visual element used to create plots.
Why does ggplot(…) do?
Initialises a ggplot object
- Declare the input data frame for a graphic and specify the set of plot aesthetics (that will be common to all subsequent laters)
What layer creates a scatterplot?
geom_point()
What are scatterplots useful for?
Displaying the relationship between two continuous variables
How do you colour points by a variable?
Within aes()
color = factor(var)
How do you plot a line graph?
geom_line()
Useful for trend lines and time-series
How do you plot a box plot?
geom_boxplot()
How many geoms should you have?
Need to have at least one, there is not upper limit
What does geom_smooth() do?
Adds a smoothed trend line to a plot, helping to visualise patterns in the data.
eg geom_smooth(method = lm_
geom_smooth(method = loess)
Default is loess for < 1000 and GAM for > 1000
What kinds of variables can you include in geom_point()
Map variables to aesthetics
- colour
- shape
- size
- alpha
How do you display the definition of a function eg geom_bar and its default parameter values?
args() function
eg args(geom_bar)
What kinds of arguments can be customised in geom_histogram()?
+ geom_histogram(stat = “bin”, binwidth = 3)
stat = “bin” is the default
What are “scales”?
Functions that control how the data is mapped to visual properties
eg position (x and y axis), colour, shape or zie
What does scale_color_brewer() do and how is it used?
Used to modify the color scheme of the points (based in colour scheme defined in ggplot aesthetics)
+ scale_color_brewer(type = “seq”, palette = 3)
How do you import ggplot?
library(ggplot2)
If using shapes to represent a categorical variable, how do you change the shapes from the default?
scale_shape_manual(values = c(16, 15, 17))
passing in a list of chosen shapes corresponding to number of categories
ANOTHER EXAMPLE
+scale_color_manual(name=’Legend’, values=c(‘D’=”grey”,
‘E’=’red’…..))
What does adding scale_size(range = c(1, 10)) do?
This function scales the size of the points based on the size variable.
range = c(1, 10) means that the smallest value of size will be mapped to a point size of 1, and the largest value will be mapped to a point size of 10.
What does facet do?
It is a way of displaying multiple plots that share the same structure and data, but differ in some aspect of their visual appearance, such as the values of a categorical variable.
How do you facet a plot?
+ facet_wrap(~var, ncol=3)
What is theme in ggplot?
Theme is a set of aesthetic attributes that can be used to customise the appearance of non-data elements.
Includes
- Axis labels
- Legend
- Title
- Background
- Font size and colour
How do you make the shapes into line shapes?
+ scale_shape(solid = FALSE)
How do you change the colour and size of plotted points?
+ geom_point(shape = 21, colour = “black”, fill = “white”, size = 5, stroke = 5)
How do you add a theme?
Add to the document
theme_set(theme_bw())
How do you set limits on the x or y axis?
xlim(0, 1)
ylim(0, 1)
To adjust them:
+coord_cartesian(xlim=c(0,3),ylim = c(0,5000))
Difference is xlim/ylim removes data points outside the range but coord_cartesian keeps them, just crops the range.