R has built-in graphics capabilities but these take quite a bit of work to get your head around.
Pairs is a pair-wise scatter plot - this is very handy for providing a visual inspection of the data and showing any correlations or clusters of data.
pairs(iris)
some models have methods for producing diagnostic plots for visual inspection.
plot(lm(Sepal.Length~Petal.Length, iris))
Term | Explanation | Example(s) |
---|---|---|
plot | A plot using the grammar of graphics | ggplot() |
aesthetics | attributes of the chart | colour, x, y |
mapping | relating a column in your data to an aesthetic | |
statistical transformation | a translation of the raw data into a refined summary | stat_density() |
geometry | the display of aesthetics | geom_line() , geom_bar() |
scale | the range of values | axes, legends |
coordinate system | how geometries get laid out | coord_flip() |
facet | a means of subsetting the chart | facet_grid() |
theme | display properties | theme_minimal() |
library(ggplot2)
p <- ggplot(data=iris)
p <- ggplot(data=iris, aes(x=Sepal.Width, y=Sepal.Length, colour=Species))
p <- p + geom_point()
p
p <- p + stat_boxplot(fill="transparent")
p
## Warning: position_dodge requires non-overlapping x intervals
p <- p + coord_flip()
p
## Warning: position_dodge requires non-overlapping x intervals
p <- p + facet_grid(.~Species)
p
p <- p + theme_minimal()
p
ggplot(data=iris, aes(x=Sepal.Width, y=Sepal.Length, colour=Species)) +
geom_point() +
stat_boxplot(fill="transparent") +
# coord_flip() + # Commented out
facet_grid(.~Species) +
theme_minimal()
iris$Sepal.Width
split by specieslibrary(ggplot2)
ggplot(iris,aes(x=Sepal.Width))+
geom_histogram()+
facet_wrap(~Species)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.