R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Including Plots

You can also embed plots, for example:

#--------- histogram with bin width = 2

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.3
library(grid)

p1 <- ggplot(mtcars, aes(x = mpg)) + 
  geom_histogram(binwidth = 2,col="black", aes(fill=..count..))

p2 <- qplot(mtcars$mpg, geom = "histogram", col = I("red"), fill = ..count.., 
      binwidth = 2)


grid.newpage()
grid.draw(rbind(ggplotGrob(p1), ggplotGrob(p2), size = "last"))

#-----------histogram with break parameter to change the bin interval

p3 <- ggplot(mtcars, aes(x = mpg)) + 
  geom_histogram(col="black", aes(fill=..count..),breaks=seq(0, 36, by=2))

p4 <- qplot(mtcars$mpg, geom = "histogram", col = I("red"), fill = ..count.., 
       breaks=seq(0, 36, by=2))

grid.newpage()
grid.draw(rbind(ggplotGrob(p3), ggplotGrob(p4), size = "last"))

#------------------------------------

p5 <- ggplot(mtcars, aes(x = mpg)) + 
  geom_histogram(col="black", aes(fill=..count..),breaks=seq(5, 35, by=5))

p6 <- qplot(mtcars$mpg, geom = "histogram", col = I("red"), fill = ..count.., 
      breaks = seq(5, 35, by=5))

grid.newpage()
grid.draw(rbind(ggplotGrob(p5), ggplotGrob(p6), size = "last"))