20 Basic data visualization cheatsheet
Yue Ma
20.1 Histogram
A histogram represents the frequencies of values of a variable bucketed into ranges. Histogram is similar to bar chat but the difference is it groups the values into continuous ranges. Each bar in histogram represents the height of the number of values present in that range.
# histogram with added parameters
hist(iris$Sepal.Length,
main="Iris Sepal Length ",
xlab="Iris sepal length",
xlim=c(4,8),
col="darkmagenta"
)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-1-1.png)
20.2 Barplot
barplot(iris$Sepal.Width)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-2-1.png)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-2-2.png)
boxplot(iris$Sepal.Width)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-3-1.png)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-3-2.png)
plot(iris$Sepal.Length)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-4-1.png)
plot(iris$Sepal.Length,iris$Species)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-4-2.png)
plot(iris)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-5-1.png)
20.3 Hexbin Binning
A hexagonal bin plot is created by covering the data range with a regular array of hexagons and coloring each hexagon according to the number of observations it covers.
library(hexbin)
library(RColorBrewer)
x <- rnorm(mean=0, 1000)
y <- rnorm(mean=1, 1000)
bin<-hexbin(x, y, xbins=40)
colors=colorRampPalette(rev(brewer.pal(11,'Spectral')))
plot(bin , colramp=colors )
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-6-1.png)
mosaicplot(HairEyeColor,shade=TRUE)
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-7-1.png)
20.4 Heatmap
Heat maps are a graphical representation of data over a given area in terms of color.
x = data.matrix(UScitiesD)
heatmap(x,main = "Distance between US")
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-8-1.png)
library(ggplot2)
data(iris,package="ggplot2")
theme_set(theme_bw())
g<-ggplot(iris,aes(Sepal.Width,Species))
g+geom_count(col="tomato3",show.ledegnd=F)+
labs(subtitle="Species vs width",
title="Counts plot")
![](basic_visualization_cheatsheet_files/figure-html/unnamed-chunk-9-1.png)