R

plotly 패키지를 이용한 원그래프 그리기

이부일 2018. 12. 27. 20:26

install.packages("tidyverse")

install.packages("plotly")

library(tidyverse)
library(plotly)


# 작업공간 설정하기
setwd("d:/DataAnalysis")


# 데이터 읽어오기
house.price <- read.csv(file                = "HousePrices.csv", 

                            header             = TRUE, 

                            stringsAsFactors  = TRUE)



# 원그래프 작성하기 01
house.price %>%
   dplyr::group_by(MSZoning) %>%
   dplyr::summarise(n = n()) %>%
   plotly::plot_ly(labels = ~MSZoning, values = ~n, type = "pie") %>%
   plotly::layout(title = "The General Zoning Classification")



# 원그래프 작성하기 02 : label을 원조각 안에 넣기
house.price %>%
   dplyr::group_by(MSZoning) %>%
   dplyr::summarise(n = n()) %>%
   plotly::plot_ly(labels = ~MSZoning, values = ~n, type = "pie", textposition = "inside") %>%
   plotly::layout(title = "The General Zoning Classification")





# 원그래프 작성하기 03 :도넛형
house.price %>%
   dplyr::group_by(MSZoning) %>%
   dplyr::summarise(n = n()) %>%
   plotly::plot_ly(labels = ~MSZoning, values = ~n) %>%
   plotly::add_pie(hole = 0.6) %>%
   plotly::layout(title = "The General Zoning Classification")