├── .Rhistory ├── .gitattributes ├── README.md ├── 3. Histogram.R ├── 4. Line Graph.R ├── 6. Box Plot.R ├── 2. Bar Chart.R ├── 5. Scatter Plot.R └── 1. Pie Chart.R /.Rhistory: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data-Visualisation-in-R 2 | Data visualization is the graphical representation of data. It involves transforming data into visual elements like charts, graphs, or maps to make it easier to understand, interpret, and communicate. 3 | -------------------------------------------------------------------------------- /3. Histogram.R: -------------------------------------------------------------------------------- 1 | # Histogram in R language 2 | 3 | a <- c(12,15,17,19,24,26,29,31,34,35,37,42,45) 4 | 5 | hist(a,xlab= "Age", ylab= "Frequency", col= "red", border= "blue") 6 | 7 | # Use of xlim and ylim parameter 8 | 9 | hist(a,xlab = "Age", ylab= "Frequecy", col= "blue", border= "red", 10 | xlim= c(10,50), ylim= c(0,5), breaks= 10) 11 | 12 | -------------------------------------------------------------------------------- /4. Line Graph.R: -------------------------------------------------------------------------------- 1 | # Line Graph in R language 2 | 3 | a<- c("4","19","9","24","14") 4 | plot(a) 5 | 6 | plot(a, type= "p") 7 | plot(a, type= "l") 8 | plot(a, type= "o") 9 | 10 | plot(a,type= "o", col= "red", xlab= "class", ylab= "Student Present") 11 | 12 | # Multiple Lines 13 | 14 | a<- c("4","19","9","24","14") 15 | b<- c("24","19","14","9","4") 16 | c<- c("24","4","19","9","14") 17 | plot(a, type="o", col= "red", xlab= "class", ylab= "Student Present") 18 | lines(b, type= "o", col= "blue") 19 | lines(c, type="o", col="yellow") 20 | -------------------------------------------------------------------------------- /6. Box Plot.R: -------------------------------------------------------------------------------- 1 | # Box Plot in R language 2 | 3 | names( mtcars) 4 | 5 | boxplot(mtcars$hp) 6 | 7 | boxplot(mtcars$hp, main= "Data", xlab= "X- Axis", ylab= "Y- Axis", col= "yellow", 8 | border= "red", horizontal= TRUE, notch= TRUE) 9 | 10 | boxplot(mpg ~ cyl, data= mtcars, xlab= "Quantity", ylab= "Miles", col= "yellow", 11 | border= "red") 12 | 13 | boxplot(mpg ~ cyl, data= mtcars, xlab= "Quantity", ylab= "Miles", main="Box", 14 | notch= TRUE, varwidth= TRUE, col= c("red", "yellow", "blue"), border= "green", 15 | names= c("High","Medium","Low")) 16 | -------------------------------------------------------------------------------- /2. Bar Chart.R: -------------------------------------------------------------------------------- 1 | # Bar Chart in R language 2 | 3 | a1 <- c(34,45,43,38,47) 4 | barplot(a1) 5 | 6 | a2 <- c(15,18,19,21) 7 | a3 <- c("East","West","North","South") 8 | barplot(a2,names.arg = a3,xlab = "Direction",ylab = "No. of People",col = "red", 9 | main = "People coming form a certain Direction",border = "black") 10 | 11 | # Group Bar Chart & Stacked Bar Chart 12 | 13 | weeks <- c("Monday","Tuesday","Wednesday","Thursday","Friday") 14 | day <- c("Morning","Afternoon","Night") 15 | values <- matrix(c(20,36,45,44,27,28,22,32,19,25,33,31,42,24,37),nrow=3,ncol=5,byrow=TRUE) 16 | barplot(values,main="Total work done on certain days",names.arg = weeks,xlab="weeks", 17 | ylab = "day",col=c("blue","green","red")) 18 | legend("topright", day , cex=0.6, fill = c("blue","green","red")) 19 | -------------------------------------------------------------------------------- /5. Scatter Plot.R: -------------------------------------------------------------------------------- 1 | # Scatter Plot in R language 2 | # plot(x, y, main, xlab, ylab, xlim, ylim, axes) - General syntax 3 | 4 | View(mtcars) 5 | dim(mtcars) 6 | names(mtcars) 7 | 8 | # Fetching two columns from mtcars 9 | 10 | data<- mtcars[,c('wt','mpg')] 11 | print(data) 12 | 13 | # Plotting the chart for cars with weight height between 2.5 and 5 and mileage 14 | # between 15 and 30 15 | 16 | plot( x= data$wt, y= data$mpg,xlab= "weight", ylab= "Mileage", 17 | xlim= c(2.5, 5), ylim= c(15, 30), 18 | main= "Weight v/s Mileage") 19 | 20 | # Scatter Plot 21 | # install.packages("ggplot2") - First time only 22 | 23 | library(ggplot2) 24 | names( mtcars) 25 | ggplot(mtcars, aes( x= drat, y= mpg))+ geom_point() 26 | # aes- aesthetic, geom- geometry 27 | ggplot(mtcars, aes( x= drat, y= mpg))+ geom_point( aes( color= factor(gear))) 28 | -------------------------------------------------------------------------------- /1. Pie Chart.R: -------------------------------------------------------------------------------- 1 | # Pie Chart in R language 2 | # A pie chart is a circular chart divided into sectors, each representing 3 | # a category of data. The size of each sector is proportional to the quantity 4 | # or frequency of the data it represents. 5 | 6 | # Data 7 | a <- c(14, 41, 36, 44) 8 | labels <- c("Cherry","Banana","Apple","Mango") 9 | pie(a,labels) 10 | pie(a,labels,main="Fruit Chart",col = rainbow(length(a))) 11 | colours <- c("blue","yellow","red","orange") 12 | pie(a,labels,main = "Fruit Chart",col=colours) 13 | 14 | # Chart Legend 15 | # legend(x,y=NULL,legend,fill,col,bg) - General Syntax 16 | 17 | legend("topright",c("Cherry","Banana","Apple","Mango"),cex=0.9, 18 | fill=colours) 19 | 20 | # 3-D Pie Chart 21 | # install.packages("plotrix") - First time only 22 | library(plotrix) 23 | b <- c(30,25,45,55) 24 | labelsa=c("East","West","North","South") 25 | pie3D(b,labels=labelsa,explode = 0.2 , main = "Directions") 26 | 27 | # Percentage 28 | c <- c(30,25,45,55) 29 | labelsb=c("East","West","North","South") 30 | pie_percent <- round(100*c/sum(c),1) 31 | pie3D(c,labels = labelsb,main="Direction",col = rainbow(length(c))) 32 | legend("topright",legend = labelsb,cex=0.6, 33 | fill=rainbow(length(c))) 34 | --------------------------------------------------------------------------------