-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVisualizing-Excel-data.R
54 lines (41 loc) · 2.13 KB
/
Visualizing-Excel-data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# "ggplot2" package
#If using for first time, uncomment this line to install "ggplot2" package
#install.packages("ggplot2")
library(ggplot2)
# "readxl" package to work with Excel files
library(readxl)
# Loading Excel file
Train_dataset = read_excel("C:\\College materials\\Others\\Learning path - R\\Train.xlsx")
View(Train_dataset)
# Scatterplot of Item_Visibility vs Item_MRP
# Plotting using facet_wrap to seperate plot using "Item_Type" attribute
ggplot(Train_dataset, aes(Item_Visibility, Item_MRP)) + geom_point(aes(color = Item_Type)) +
facet_wrap("Item_Type") + scale_size_area() +theme(legend.position = "none")
#Area plot - Trend of Item_Outlet_Sales
ggplot(Train_dataset, aes(Item_Outlet_Sales)) + geom_area(stat = "bin", bins = 40)
# Heat Map - MRP of each Item_Type in each Outlet_Type
# Writing X labels vertically
ggplot(Train_dataset, aes(Outlet_Type, Item_Type)) +
geom_raster(aes(fill = Item_MRP)) +
theme(axis.text.x = element_text(angle = 90))
# Stacked Barplot
ggplot(Train_dataset, aes(Outlet_Location_Type, fill = Outlet_Type)) + geom_bar()
##############################################################################################
# Converting data frame into .xlsx file
# "xlsx" package
# If using for first time, uncomment this line to install "xlsx" package
# install.packages("xlsx")
library(xlsx)
df_sample = data.frame(stud = c("SK7", "CR7", "Messi"), M1 = c(98, 90, 100), M2 = c(80, 90, 95),
row.names = c("S1", "S2", "S3"))
print(df_sample)
# File will be generated by default in "Documents"
write.xlsx(df_sample, file = "Generated-excel.xlsx", row.names = FALSE)
# Creating a workbook with multiple sheets and populating each sheet with data
sample_mul_wb = createWorkbook()
car_df = createSheet(wb = sample_mul_wb, sheetName = "MTCARS Dataset")
iris_df = createSheet(wb = sample_mul_wb, sheetName = "IRIS Dataset")
addDataFrame(x = mtcars, sheet = car_df)
addDataFrame(x = iris, sheet = iris_df)
saveWorkbook(sample_mul_wb, file = "Datasets.xlsx")
##############################################################################################