Example 1: Using iris dataset

# Nessasory libraries
library(ggplot2)
library(dplyr)

str(iris)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
# In iris data set we have 4 cotinuous numerical variable and,
# one categorical(factor) variable.
table(iris$Species)
## 
##     setosa versicolor  virginica 
##         50         50         50
ggplot(data = iris)

ggplot(data = iris, aes(x=Sepal.Length, y=Petal.Length))

ggplot(data = iris, aes(x=Sepal.Length, y=Petal.Length)) + geom_point()

ggplot(data = iris, aes(x=Sepal.Length, y=Petal.Length)) + geom_point()

ggplot(data = iris, aes(x=Sepal.Length, y=Petal.Length, col=Species)) + geom_point()

ggplot(data = iris, aes(x=Sepal.Length, y=Petal.Length, col=Species, shape=Species)) +
       geom_point() + xlab("Sepal Length") + ylab("Petal Length")

Example 2:

# Nessasory libraries
library(ggplot2)
library(dplyr)


# First import the data set
londonBike <- read.csv("londonBike.csv")
# Since in this data set x column is not usable 
londonBike %>% select(c(-1)) -> mydata

# First lets underestand of this data set
# we have 
table(mydata$hour)
## 
##   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19 
## 724 724 721 721 721 721 726 726 724 727 725 727 729 728 728 729 730 728 728 727 
##  20  21  22  23 
## 727 726 725 722
table(mydata$season)
## 
##    0    1    2    3 
## 4394 4387 4303 4330
table(mydata$day)
## 
##    1    2    3    4    5    6    7 
## 2508 2505 2489 2492 2450 2465 2505
table(mydata$is_holiday)
## 
##     0     1 
## 17030   384
table(mydata$weatherCond)
## 
##    1    2    3    4    7   10   26 
## 6150 4034 3551 1464 2141   14   60
# Lets do some basic graphing
# 1). Scatter plot
plot(mydata$temp ~ mydata$count)

plot(mydata$humidity ~ mydata$count)

plot(mydata$humidity ~ mydata$wind_speed, 
     ylab = "Humidity", xlab = "Wind Speed", main = "Humidity vs Wind Speed",
     col = "blue", pch = 16)

# 2). Histogram
hist(mydata$count)

hist(mydata$humidity)

hist(mydata$wind_speed)

hist(mydata$temp, 
     xlab = "Temperature", main = "Histogram of Temperature", col = "purple")

# 3). Box plot
boxplot(mydata$temp)

boxplot(mydata$humidity)

boxplot(mydata$wind_speed)

boxplot(mydata$count ~ mydata$is_holiday,
       xlab = "Is Holiday", ylab = "Bike count", 
       main = "Bike count based on Holiday or not",
       col = "green", pch = 16)

boxplot(mydata$count ~ mydata$day,
        xlab = "Days", ylab = "Bike count", 
        main = "Bike count based on Days",
        col = "purple", pch = 16)

boxplot(mydata$count ~ mydata$season,
        xlab = "Seasons", ylab = "Bike count", 
        main = "Bike count based on Seasons",
        col = "red", pch = 16)

boxplot(mydata$count ~ mydata$hour,
        xlab = "Hours", ylab = "Bike count", 
        main = "Bike count based on Hours",
        col = "yellow", pch = 16)

# Now we do some more on these graphs by ggplot
ggplot(data = mydata)

ggplot(data = mydata, aes(y = count, x = hour))

ggplot(data = mydata) + geom_boxplot(aes(x=factor(hour), 
                                         y=count, fill=factor(hour)), 
                                     position=position_dodge(1),
                                     show.legend = FALSE) +
                                     ylab("Number of rentals per hour") + 
                                     xlab("Hour of the day")

# Here we use ggplot to create some awsome graphs.

# Nessasory libraries
library(ggplot2)
library(dplyr)

# We use LondonBike data set to perform this.

# ?select
# also like this >londonBike %>% select(c(-1)) -> mydata
select(londonBike, c(-1)) -> lb

#****************** ggplot *********************

# 1). Histogram
ggplot(data = lb)

ggplot(data = lb, aes(x = count))

ggplot(data = lb, aes(x = count)) + geom_histogram(bins = 75,
                                                   fill = "green",
                                                   col = "purple")

# positioning
ggplot(data = lb, aes(x=humidity, fill=is_holiday)) + geom_histogram(bins = 75)