This plotly analysis evaluates the profits and sales of items under the Superstore dataset from Tableau.
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
superstore <- read.xlsx('C:/Users/sgpoh/Downloads/Full-Sales-Superstore-Dataset.xlsx')
head(superstore)
## Category City Country Customer.Name Manufacturer
## 1 Office Supplies Houston United States Darren Powers Message Book
## 2 Office Supplies Naperville United States Phillina Ober GBC
## 3 Office Supplies Naperville United States Phillina Ober Avery
## 4 Office Supplies Naperville United States Phillina Ober SAFCO
## 5 Office Supplies Philadelphia United States Mick Brown Avery
## 6 Office Supplies Athens United States Jack O'Briant Dixon
## Order.Date Order.ID Postal.Code
## 1 40547 CA-2011-103800 77095
## 2 40548 CA-2011-112326 60540
## 3 40548 CA-2011-112326 60540
## 4 40548 CA-2011-112326 60540
## 5 40549 CA-2011-141817 19143
## 6 40550 CA-2011-106054 30605
## Product.Name
## 1 Message Book, Wirebound, Four 5 1/2" X 4" Forms/Pg., 200 Dupl. Sets/Book
## 2 GBC Standard Plastic Binding Systems Combs
## 3 Avery 508
## 4 SAFCO Boltless Steel Shelving
## 5 Avery Hi-Liter EverBold Pen Style Fluorescent Highlighters, 4/Pack
## 6 Dixon Prang Watercolor Pencils, 10-Color Set with Brush
## Region Segment Ship.Date Ship.Mode State Sub-Category
## 1 Central Consumer 40551 Standard Class Texas Paper
## 2 Central Home Office 40552 Standard Class Illinois Binders
## 3 Central Home Office 40552 Standard Class Illinois Labels
## 4 Central Home Office 40552 Standard Class Illinois Storage
## 5 East Consumer 40556 Standard Class Pennsylvania Art
## 6 South Corporate 40551 First Class Georgia Art
## Discount Number.of.Records Profit Profit.Ratio Quantity Sales
## 1 0.2 1 6 0.34 2 16
## 2 0.8 1 -5 -1.55 2 4
## 3 0.2 1 4 0.36 3 12
## 4 0.2 1 -65 -0.24 3 273
## 5 0.2 1 5 0.25 3 20
## 6 0.0 1 5 0.41 3 13
state_region <- read.xlsx('C:/Users/sgpoh/Downloads/US_States_Region.xlsx')
head(state_region)
## State Region
## 1 Alabama South
## 2 Arizona West
## 3 Arkansas South
## 4 California West
## 5 Colorado West
## 6 Connecticut East
mean_sales <- aggregate(Sales ~ State, superstore, mean)
mean_profit <- aggregate(Profit ~ State, superstore, mean)
mean_superstore <- merge(mean_sales, mean_profit, by="State")
supersuperstore_agg <- merge(state_region, mean_superstore, by="State")
names(mean_superstore)[names(mean_superstore) == 'Sales'] <- 'Average Sales in USD'
names(mean_superstore)[names(mean_superstore) == 'Profit'] <- 'Average Profit in USD'
x <- list(title = "Average Sales in USD")
y <- list(title = "Average Profit in USD")
plot_ly(data = supersuperstore_agg , x = ~Sales, y = ~Profit, color = ~Region) %>% layout(xaxis = x, yaxis = y)
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plot.ly/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
```