Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Data Designer
Class 11
ggmap & leaflet
꿈꾸는데이터디자이너 시즌2
Map
꿈꾸는데이터디자이너 시즌2
# install.packages('maps')
library(maps)
library(ggplot2)
asia = map_data('world',
region = c('Japan',
'Chi...
꿈꾸는데이터디자이너 시즌2
ggplot(asia,
aes(x = long, y = lat, group = group)) +
geom_polygon(fill = 'white', colour = 'black')
20
30
...
꿈꾸는데이터디자이너 시즌2
ggplot(asia,
aes(x = long, y = lat, group = group)) +
geom_polygon(fill = 'white', colour = 'black') +
coor...
꿈꾸는데이터디자이너 시즌2
ggplot(asia,
aes(x = long, y = lat, group = group)) +
geom_polygon(fill = 'white', colour = 'black') +
coor...
꿈꾸는데이터디자이너 시즌2
geocoding
꿈꾸는데이터디자이너 시즌2
geocoding
주소 위도,경도
꿈꾸는데이터디자이너 시즌2
# install.packages('ggmap')
library(ggmap)
geocode('Seoul', source = 'google')
lon lat
126.978 37.56654
꿈꾸는데이터디자이너 시즌2
geocode('Seoul',
source = 'google',
output = 'latlona')
lon lat address
126.978 37.56654 seoul, south korea
꿈꾸는데이터디자이너 시즌2
geocode(enc2utf8(' '),
source = 'google')
lon lat
126.978 37.56654
꿈꾸는데이터디자이너 시즌2
geocode(enc2utf8(' '),
source = 'google',
output = 'latlona')
lon lat address
126.978 37.56654 seoul, south...
꿈꾸는데이터디자이너 시즌2
geocode(enc2utf8(' &language=ko'),
source = 'google',
output = 'latlona')
lon lat address
126.978 37.56654
꿈꾸는데이터디자이너 시즌2
ggmap::mutate_geocode
주소가 포함된 data.frame -> 위도, 경도를 추가한다
주소가 담겨있는 열 이름(두 번째 인자)에 따옴표를 붙이지 않는다
mutate_geocod...
꿈꾸는데이터디자이너 시즌2
station_list = c('시청역', '을지로입구역', '을지로3가역',
'을지로4가역', '동대문역사문화공원역', '신당역', '상왕십리역',
'왕십리역', '한양대역', '뚝섬역', ...
꿈꾸는데이터디자이너 시즌2
# data.frame에 검색하려는 주소를 열로 저장한다
station_df = data.frame(station_list,
stringsAsFactors = FALSE)
# UTF-8로 인코...
꿈꾸는데이터디자이너 시즌2
station_list
1 시청역
2 을지로입구역
3 을지로3가역
4 을지로4가역
5 동대문역사문화공원역
6 신당역
7 상왕십리역
8 왕십리역
9 한양대역
10 뚝섬역
ggmap::mutate...
꿈꾸는데이터디자이너 시즌2
ggmap
꿈꾸는데이터디자이너 시즌2
qmap('seoul', zoom = 11)
qmap('seoul', zoom = 11, color = 'bw')
qmap('seoul', zoom = 11, maptype = 'roadmap...
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
qmap('seoul', zoom = 11, source = 'stamen',
maptype = 'watercolor')
qmap('seoul', zoom = 11, source = 'stam...
꿈꾸는데이터디자이너 시즌2
지도 그리기 (stamen design)
ggmap::qmap
꿈꾸는데이터디자이너 시즌2
seoul_lonlat = unlist(
geocode('seoul', source='google'))
qmap(seoul_lonlat, zoom = 11,
source = 'stamen', ...
꿈꾸는데이터디자이너 시즌2
seoul_map <- qmap('Seoul', zoom = 11,
source = 'stamen', maptype = 'toner')
seoul_map +
geom_point(data = s...
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
wifi_data = read.csv('wifi_data.csv',
stringsAsFactors = FALSE)
seoul_map +
geom_point(data = wifi_data, ae...
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
seoul_map +
geom_polygon(data = wifi_data,
aes(x=lon, y=lat, fill=..level..),
stat = 'density2d',
alpha = 0...
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
leaflet
꿈꾸는데이터디자이너 시즌2
# install.packages('leaflet')
library(leaflet)
leaflet(wifi_data) %>%
setView(lng = seoul_lonlat[1],
lat = ...
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
leaflet(wifi_data) %>%
setView(lng = seoul_lonlat[1],
lat = seoul_lonlat[2], zoom = 11) %>%
addProviderTile...
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
leaflet(wifi_data) %>%
setView(lng = seoul_lonlat [1],
lat = seoul_lonlat[2], zoom = 11) %>%
addProviderTil...
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
부록
꿈꾸는데이터디자이너 시즌2
htmlwidgets
꿈꾸는데이터디자이너 시즌2
꿈꾸는데이터디자이너 시즌2
# install.packages('networkD3')
library(networkD3)
data(MisLinks, MisNodes)
forceNetwork(Links = MisLinks, ...
꿈꾸는데이터디자이너 시즌2
# install.packages('d3heatmap')
library(d3heatmap)
d3heatmap(mtcars, scale="column", colors="Blues")
꿈꾸는데이터디자이너 시즌2
# install.packages('DT')
library(DT)
datatable(iris)
[week11] R_ggmap, leaflet
Upcoming SlideShare
Loading in …5
×

[week11] R_ggmap, leaflet

2,161 views

Published on

꿈데디 교육자료

Published in: Data & Analytics
  • DOWNLOAD THAT BOOKS/FILE INTO AVAILABLE FORMAT - (Unlimited) ......................................................................................................................... ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes Christian, Classics, Comics, Contemporary, Cookbooks, Art, Biography, Business, Chick Lit, Children's, Manga, Memoir, Music, Science, Science Fiction, Self Help, History, Horror, Humor And Comedy, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ..................................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ..................................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ..................................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

[week11] R_ggmap, leaflet

  1. 1. Data Designer Class 11 ggmap & leaflet
  2. 2. 꿈꾸는데이터디자이너 시즌2 Map
  3. 3. 꿈꾸는데이터디자이너 시즌2 # install.packages('maps') library(maps) library(ggplot2) asia = map_data('world', region = c('Japan', 'China', 'North Korea', 'South Korea'))
  4. 4. 꿈꾸는데이터디자이너 시즌2 ggplot(asia, aes(x = long, y = lat, group = group)) + geom_polygon(fill = 'white', colour = 'black') 20 30 40 50 90 110 130 long lat
  5. 5. 꿈꾸는데이터디자이너 시즌2 ggplot(asia, aes(x = long, y = lat, group = group)) + geom_polygon(fill = 'white', colour = 'black') + coord_map() # metacator 투영법 20 30 40 50 90 110 130 long lat
  6. 6. 꿈꾸는데이터디자이너 시즌2 ggplot(asia, aes(x = long, y = lat, group = group)) + geom_polygon(fill = 'white', colour = 'black') + coord_map("polyconic") # polyconic 투영법 20 30 40 50 90 110 130 long lat
  7. 7. 꿈꾸는데이터디자이너 시즌2 geocoding
  8. 8. 꿈꾸는데이터디자이너 시즌2 geocoding 주소 위도,경도
  9. 9. 꿈꾸는데이터디자이너 시즌2 # install.packages('ggmap') library(ggmap) geocode('Seoul', source = 'google') lon lat 126.978 37.56654
  10. 10. 꿈꾸는데이터디자이너 시즌2 geocode('Seoul', source = 'google', output = 'latlona') lon lat address 126.978 37.56654 seoul, south korea
  11. 11. 꿈꾸는데이터디자이너 시즌2 geocode(enc2utf8(' '), source = 'google') lon lat 126.978 37.56654
  12. 12. 꿈꾸는데이터디자이너 시즌2 geocode(enc2utf8(' '), source = 'google', output = 'latlona') lon lat address 126.978 37.56654 seoul, south korea
  13. 13. 꿈꾸는데이터디자이너 시즌2 geocode(enc2utf8(' &language=ko'), source = 'google', output = 'latlona') lon lat address 126.978 37.56654
  14. 14. 꿈꾸는데이터디자이너 시즌2 ggmap::mutate_geocode 주소가 포함된 data.frame -> 위도, 경도를 추가한다 주소가 담겨있는 열 이름(두 번째 인자)에 따옴표를 붙이지 않는다 mutate_geocode(data.frame, address_column_name, source = 'google')
  15. 15. 꿈꾸는데이터디자이너 시즌2 station_list = c('시청역', '을지로입구역', '을지로3가역', '을지로4가역', '동대문역사문화공원역', '신당역', '상왕십리역', '왕십리역', '한양대역', '뚝섬역', '성수역', '건대입구역', '구의역', '강변역', '잠실나루역', '잠실역', '신천역', '종합운동장역', '삼성역', '선릉역', '역삼역', '강남역', '2호선 교대역', '서초역', '방배역', '사당역', '낙성대역', '서울대입구역', '봉천역', '신림역', '신대방역', '구로디지털단지역', '대림역', '신도림역','문래역', '영등포구청역', '당산역', '합정역', '홍대입구역', '신촌역', '이대역', '아현역', '충정로역') 2호선 지하철역 목록
  16. 16. 꿈꾸는데이터디자이너 시즌2 # data.frame에 검색하려는 주소를 열로 저장한다 station_df = data.frame(station_list, stringsAsFactors = FALSE) # UTF-8로 인코딩을 변경한다 station_df$station_list = enc2utf8(station_df$station_list) # mutate_geocode 함수를 이용해 좌표를 검색한다 station_lonlat = mutate_geocode(station_df, station_list, source = 'google') ggmap::mutate_geocode
  17. 17. 꿈꾸는데이터디자이너 시즌2 station_list 1 시청역 2 을지로입구역 3 을지로3가역 4 을지로4가역 5 동대문역사문화공원역 6 신당역 7 상왕십리역 8 왕십리역 9 한양대역 10 뚝섬역 ggmap::mutate_geocode station_list lon lat 1 시청역 126.9771 37.56544 2 을지로입구역 126.9827 37.56606 3 을지로3가역 126.9926 37.56629 4 을지로4가역 126.9976 37.56661 5 동대문역사문화공원역 127.0092 37.56564 6 신당역 127.0195 37.56567 7 상왕십리역 127.0289 37.56450 8 왕십리역 127.0373 37.56198 9 한양대역 127.0437 37.55562 10 뚝섬역 127.0473 37.54724
  18. 18. 꿈꾸는데이터디자이너 시즌2 ggmap
  19. 19. 꿈꾸는데이터디자이너 시즌2 qmap('seoul', zoom = 11) qmap('seoul', zoom = 11, color = 'bw') qmap('seoul', zoom = 11, maptype = 'roadmap') qmap('seoul', zoom = 11, maptype = 'satellite') qmap('seoul', zoom = 11, maptype = 'hybrid') 지도 그리기 (google) ggmap::qmap
  20. 20. 꿈꾸는데이터디자이너 시즌2
  21. 21. 꿈꾸는데이터디자이너 시즌2 qmap('seoul', zoom = 11, source = 'stamen', maptype = 'watercolor') qmap('seoul', zoom = 11, source = 'stamen', maptype = 'toner') 지도 그리기 (stamen design) ggmap::qmap
  22. 22. 꿈꾸는데이터디자이너 시즌2 지도 그리기 (stamen design) ggmap::qmap
  23. 23. 꿈꾸는데이터디자이너 시즌2 seoul_lonlat = unlist( geocode('seoul', source='google')) qmap(seoul_lonlat, zoom = 11, source = 'stamen', maptype = 'toner') 특정 위도, 경도를 중심으로 지도 그리기 ggmap::qmap
  24. 24. 꿈꾸는데이터디자이너 시즌2 seoul_map <- qmap('Seoul', zoom = 11, source = 'stamen', maptype = 'toner') seoul_map + geom_point(data = station_lonlat, aes(x = lon, y = lat), colour = 'green', size = 4) 지도 위에 레이어 끼얹기 mapping with ggmap + ggplot2
  25. 25. 꿈꾸는데이터디자이너 시즌2
  26. 26. 꿈꾸는데이터디자이너 시즌2 wifi_data = read.csv('wifi_data.csv', stringsAsFactors = FALSE) seoul_map + geom_point(data = wifi_data, aes(x=lon, y=lat))+ facet_wrap(~div) 지도 위에 레이어 끼얹기 mapping with ggmap + ggplot2
  27. 27. 꿈꾸는데이터디자이너 시즌2
  28. 28. 꿈꾸는데이터디자이너 시즌2 seoul_map + geom_polygon(data = wifi_data, aes(x=lon, y=lat, fill=..level..), stat = 'density2d', alpha = 0.3) + scale_fill_gradient(low = '#C6DBEF', high = '#08306B') + facet_wrap(~div) 지도 위에 레이어 끼얹기 mapping with ggmap + ggplot2
  29. 29. 꿈꾸는데이터디자이너 시즌2
  30. 30. 꿈꾸는데이터디자이너 시즌2 leaflet
  31. 31. 꿈꾸는데이터디자이너 시즌2 # install.packages('leaflet') library(leaflet) leaflet(wifi_data) %>% setView(lng = seoul_lonlat[1], lat = seoul_lonlat[2], zoom = 11) %>% addTiles() %>% addCircles(lng = ~lon, lat = ~lat) 설치하기 + 지도 그리기(default : OpenStreetMap) mapping with leaflet
  32. 32. 꿈꾸는데이터디자이너 시즌2
  33. 33. 꿈꾸는데이터디자이너 시즌2 leaflet(wifi_data) %>% setView(lng = seoul_lonlat[1], lat = seoul_lonlat[2], zoom = 11) %>% addProviderTiles('Stamen.Toner') %>% addCircles(lng = ~lon, lat=~lat) leaflet(wifi_data) %>% setView(lng = seoul_lonlat [1], lat = seoul_lonlat[2], zoom = 11) %>% addProviderTiles('CartoDB.Positron') %>% addCircles(lng = ~lon, lat=~lat) 지도 그리기(Third Party Tiles) mapping with leaflet
  34. 34. 꿈꾸는데이터디자이너 시즌2
  35. 35. 꿈꾸는데이터디자이너 시즌2 leaflet(wifi_data) %>% setView(lng = seoul_lonlat [1], lat = seoul_lonlat[2], zoom = 11) %>% addProviderTiles('Stamen.Toner') %>% addCircles(lng = ~lon, lat=~lat, popup = ~div) popup(tooltip) 설정하기 mapping with leaflet
  36. 36. 꿈꾸는데이터디자이너 시즌2
  37. 37. 꿈꾸는데이터디자이너 시즌2 부록
  38. 38. 꿈꾸는데이터디자이너 시즌2 htmlwidgets
  39. 39. 꿈꾸는데이터디자이너 시즌2
  40. 40. 꿈꾸는데이터디자이너 시즌2 # install.packages('networkD3') library(networkD3) data(MisLinks, MisNodes) forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = 'source', Target = 'target', Value = 'value', NodeID = 'name', Group = 'group', opacity = 0.6)
  41. 41. 꿈꾸는데이터디자이너 시즌2 # install.packages('d3heatmap') library(d3heatmap) d3heatmap(mtcars, scale="column", colors="Blues")
  42. 42. 꿈꾸는데이터디자이너 시즌2 # install.packages('DT') library(DT) datatable(iris)

×