Link to Rpubs: https://rpubs.com/nikeshrpubs/1027800

Problem 1:::

Discussion

This plotly pie chart displays breakdown of population in southern North Dakota in 2010 by ethnic groups. Each ethnic group can be identified by a distinct color. The pie chart displays numeric values for percentage breakdown. When hovering the cursor over a segment of the pie chart, three attributes - ethnicity, population count, and percentage are displayed for each segment.
This interactive plotly pie chart makes it easier for viewers to get insights into demographics in southern North Dakota.

Code

library(readxl)
library(plotly)
library(ggplot2)
data1 <- read_excel("Pie Chart data.xlsx")
plot_ly(data1, labels = data1$`Ethnic Groups`, values = data1$Population, type = 'pie') %>% layout(title = '<b>Population by ethnic groups in Southern North Dakota in 2010</b>')

Problem 2:::

Discussion

Diamonds dataset is used that contains the prices and other attributes of more than 10,000 diamonds. The attributes of interest are price (in USD), carat (i.e. weight of diamond), color [i.e. D (best color),E,F,G,H,I,J (worst color)], and cut (i.e. good,better,best). I am interested in knowing (i) if there is proportional relationship between price and carat, & (ii) how does diamond prices vary with its color and cut.

To investigate, an animated scatter plotly graph of carat vs price is created. The frame is set to vary by diamond color and data points are colored based on type of cut.

The plot strongly suggests that price and carat are directly proportional. Also, the data points for ‘Better’ diamond cut type is sandwiched between ‘Best’ on top and ‘Good’ on bottom inferring that diamonds get costlier when going from ‘Good’ to ‘Best’ cut type. Lastly, the plot suggests there is no definite price trend for diamond color from D to J.

Code

t1 <- list(
  family = "Times New Roman",
  size = 20,
  color = "red")
t2 <- list(
  family = "Times New Roman",
  size = 18,
  color = "green")
t3 <- list(
  family = "Times New Roman",
  size = 18,
  color = "blue")
data2 <- read.csv("diamonds.csv")
data2 %>% 
  plot_ly(x = data2$carat, y = data2$price) %>% 
  layout(title = list(text = "<b>Exploration of Diamond Prices Based on Color</b>", font=t1),  
         xaxis = list(title=list(text="<b>Carat</b>",font = t2)),
         yaxis = list(title = list(text ="<b>Price in USD</b>", font = t2)),
         legend = list(title=list(text="<b> Diamond Cut Type </b>", font = t3)))%>%
  add_markers(frame = data2$color,
               color = data2$cut )