r
  • heatmap
  • 2015-01-21 2 views 0 likes 
    0

    임 테이블 country.txt 파일의 열지도를 만들려고 :R의 세계적인 히트 맵 만드는 방법 - 대륙의 수준을

    : 나는 등의지도를 볼 수 있다는 사실을 알고

    Region Value 
    Europe 5 
    Africa 6 
    America 7 
    Asia 8 
    

    map.world <- map_data(map = "world") 
    mapCountryData(sPDF,nameColumnToPlot = 'continent') 
    

    데이터를지도에 어떻게 적용합니까? 나는. 나는 가장 높은 가치를 가진 대륙이 녹색이라고 말해야하고 가장 낮은 가치를 가진 대륙은 적색이되기를 바란다.

    답변

    2

    다음은 함께 작업 할 수있는 단순한 대륙 모양 파일입니다. 나는 투사를 변경하고 내가 간행물에 빠뜨리는 것 뭔가 남극 대륙을 제거 할 수 있지만 이것은 당신에게 시작주는 것 다음에 대표로 여기

    enter image description here

    library(rgdal) 
    library(rgeos) 
    library(ggplot2) 
    library(httr) 
    
    url <- "https://gist.githubusercontent.com/hrbrmstr/91ea5cc9474286c72838/raw/f3fde312c9b816dff3994f39f2bcda03209eff8f/continents.json" 
    stop_for_status(GET(url, write_disk("continents.json"))) 
    continents <- readOGR("continents.json", "OGRGeoJSON") 
    continents_map <- fortify(continents, region="CONTINENT") 
    
    data <- read.table(text="id value 
    Europe 5 
    Africa 6 
    America 7 
    Asia 8", header=TRUE, stringsAsFactors=FALSE) 
    
    
    gg <- ggplot() 
    gg <- gg + geom_map(data=continents_map, 
            map=continents_map, 
            aes(x=long, y=lat, map_id=id), 
            color="black") 
    gg <- gg + geom_map(data=data, 
            map=continents_map, 
            aes(map_id=id, fill=value), 
            color="black") 
    gg <- gg + scale_fill_distiller("PuBu") # needs latest ggplot2 
    gg <- gg + coord_equal() 
    gg <- gg + theme_bw() 
    gg <- gg + labs(x=NULL, y=NULL) 
    gg <- gg + theme(panel.border=element_blank()) 
    gg <- gg + theme(panel.grid=element_blank()) 
    gg 
    
    이 대륙의 이름이됩니다 shapefile :

    [email protected]$CONTINENT 
    ## [1] Asia   North America Europe  Africa  South America 
    ## [6] Oceania  Australia  Antarctica 
    
    +0

    그래서 github 링크는 '지리적지도'경계를 나타냅니다. 맞습니까? 좋아, 내가 뭘 찾고 있었는지, 어떻게 색상을 변경합니까? 스크립트의 어느 부분이 '블루스'에 대한 책임이있는 지 알 수 없으므로 ... – BlueSkies

    +1

    'scale_fill_distiller ("PuBu")' –

    +0

    가장 좋은 해결책은 아니 겠지만 일을하는 방식은 ... 무엇이 궁금합니다. 다른 더 나은 옵션이 있습니다. – BlueSkies

    관련 문제