-
How to clear R studio console
CNTRL + L
-
installing ggplot libararies
install.packages('ggplot2', repos='http://cran.us.r-project.org')
- import ggplot
library(ggplot2)
- How to load dataset
cricket <- read.csv("C:/Users/User/Downloads/cs.csv")
- How to view data
View(cricket)
- To get data from head
To get first 7 rows | To get all rows except last 7 |
head(cricket,7) |
head(cricket,-7) |
![]() |
- To get data from tail
To get last 7 rows | To get all rows except last 7 |
tail(cricket,7) |
tail(cricket,-7) |
![]() |
- To summaries dataset
summary(cricket)
- Creating pie-chart
pie(table(cricket$Country), main = "Pie Chart of the cricket data set of contries", col = c("orange","pink","red","blue","yellow","green","violet"), radius = 1)
- Plotting Histogram
hist(cricket$Sixes, col=c("green", "red", "blue"), xlab="Number of Sixes", ylab= "Frequncy of Sixes", main="Histogram of Sixes")
- Plotting Scatterplot
plot(cricket$Fifties~cricket$Hundreds,xlab="Hundreds" ,ylab="Fifties", main="Scatterplot for Hundreds vs Fifties", col=c("blue", "red"),pch=16)
- Plotting Scatterplot with background theme and symbols
ggplot(data=cricket,aes(y=Fifties,x=Hundreds,col=Country))+geom_point()
- Plotting Barchart with background theme and symbols
ggplot(data=cricket,aes(x=Hundreds,fill=Country))+geom_histogram(bins=50)
- Alternative of Histogram
ggplot(data=cricket,aes(x=Hundreds))+geom_freqpoly()