I am taking the inbuilt data set in R.The Data set is mtcars. It has 32 observations and 11 variables. This is my first GGplot using in built data set.Firstly, I will download the library ggplot2 and then load it into R console before calling the mtcars data set.
library(tidyverse)
library(ggplot2)
my_data <- mtcars
# Histogram ---------------------------------------------------------------
#it is used for one variable to measure its count
ggplot(data = my_data,aes(x=mpg)) + #you will get a plain plot
geom_histogram(binwidth = 5,colour='red',fill='blue')+ ggtitle('distribution of mpg')+
ylab('count of mpg')+ xlab('miles per gallon')+
xlim(0,50)+ylim(0,25)
ggplot() function was used with arguments as MTG cars for data, mpg on X-Axis. only ggplot will gives you a plain sheet without geoms. geom_histogram plots the hist curve on the graph and aesthetic mpg(miles per gallon) and its count on the y-axis. GGtitile gives the name for the plot. xlim() and ylim() functions limits the scales on the respective axes with xlab() and ylab() function used for nameing the axes.