Section 21 One Numeric: Other
21.1 Rug plot:
The function goem_rug
adds a rug representation (1-d plot) of the data to the plot.
data(iris)
# geom_rug
g <- ggplot(data=iris, mapping=aes(Sepal.Length))
g <- g + geom_histogram(mapping=aes(y=..density..),
binwidth=0.10, fill='white', colour='blue')
g <- g + geom_density(alpha=0.2, fill='lightgreen', colour='purple')
g <- g + labs(title='Histogram & Density plot of Sepal Length',
subtitle='Based on Iris data',
x='Sepal Length (cm)',
y='Density')
g <- g + geom_rug()
g + theme_bw()
data(faithful)
# geom_rug
g <- ggplot(data=faithful, mapping=aes(eruptions))
g <- g + geom_histogram(mapping=aes(y=..density..),
binwidth=0.10, fill='white', colour='blue')
g <- g + geom_density(alpha=0.2, fill='lightgreen', colour='purple')
g <- g + geom_rug()
g <- g + labs(title='Histogram & Density plot of Eruption',
subtitle='Based on old faithful data',
x='Eruption time (mins)',
y='Density')
g + theme_bw()
# geom_rug with additional options
g <- ggplot(data=faithful, mapping=aes(eruptions))
g <- g + geom_histogram(mapping=aes(y=..density..),
binwidth=0.10, fill='white', colour='blue')
g <- g + geom_density(alpha=0.2, fill='lightgreen', colour='purple')
g <- g + geom_rug(alpha=0.5, colour='red')
g <- g + labs(title='Histogram & Density plot of Eruption',
subtitle='Based on old faithful data',
x='Eruption time (mins)',
y='Density')
g + theme_bw()
21.2 Dot plot:
The function geom_dotplot
draws a Cleveland dot plot.
data(mtcars)
# geom_dotplot()
g <- ggplot(data=mtcars, mapping=aes(mpg))
g <- g + geom_dotplot()
g
# binwidth
g <- ggplot(data=mtcars, mapping=aes(mpg))
g <- g + geom_dotplot(binwidth=1.5)
g
# alpha, fill
g <- ggplot(data=mtcars, mapping=aes(mpg))
g <- g + geom_dotplot(binwidth=1.5, alpha=0.5, fill='blue')
g
# labs, theme_bw()
g <- ggplot(data=mtcars, mapping=aes(mpg))
g <- g + geom_dotplot(binwidth=1.5, alpha=0.5, fill='blue')
g <- g + labs(title='Gas Milage for Car Models',
subtitle='Based on mtcars data',
x='Miles Per Gallon',
y='Proportion')
g + theme_bw()
21.3 Example:
data(warpbreaks)
Draw histogram, density plot along with rug plot of the variable
breaks
Discuss the plot
Transform the data using log-transformation and redraw the plots