R: 国に色をつけるもっとも簡単な方法, ggplot2 corrected, ver. 2

ggplot2のmapで簡単に国に色をつけます。

 

https://rpubs.com/vprabhuram/222767

 

 

次のregion1で国名を指定します。

 

library(tidyverse)
world_map_data<-map_data("world")
world2_map_data<-map_data("world2")
#us_state_map_date <- map_data("state")
region1 <- c("China", "Japan", "South Korea", "Indonesia")
ggplot() +
geom_polygon(data=world2_map_data, aes(x=long,y=lat,group=group),
color = "grey", size = 0.1, fill="gainsboro") +
geom_polygon(data = subset(world_map_data, world_map_data$region == region1)
, aes(x=long,y=lat, group = group),
fill= "red", size = 0.1)
 

 

米国をいれて二色にわけました。

 

 

library(tidyverse)
world_map_data <- map_data("world")
world2_map_data <- map_data("world2")
us_state_map_date <- map_data("state")

ggplot() +
  geom_polygon(data=world2_map_data, aes(x=long,y=lat,group=group), color = "grey", size = 0.1, fill="gainsboro") +
  geom_polygon(data = subset(world_map_data, world_map_data$region == c("Japan","Nepal")), aes(x=long,y=lat, group = group), 
               fill="red", size = 0.1) +
  geom_polygon(data = subset(world_map_data, world_map_data$region == c("China","India")), aes(x=long,y=lat, group = group), 
               fill= "royalblue", size = 0.1) +
geom_polygon(data = subset(world2_map_data, world2_map_data$region == "USA"), aes(x=long,y=lat, group = group), 
             fill= "royalblue", size = 0.1)

 

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.