library(sp)

library(sf)

library(tidyr)

library(spatstat.sparse)

library(REdaS)

library(plotly)


co <- read.csv('d://kaggle/dataset_5/countries_of_the_world.csv')


df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')

df[,2] <- log(as.numeric(df[,2]))


co[,2] <- log(as.numeric(co[,2]))


elev <- read.csv("d://filebox/dataset_4/csv/elevp.csv")


qk <- read.csv('d://filebox/csv/earthquakes.csv')

qk[,2] <- log(as.numeric(qk[,2]))


deg2rad <- function(deg) {

  (deg * pi) / (180)

}


fig1 <- function(x,y){

  2*x+x+1=y

}


linear_fun<-function(x){

  4*x^2+2*x+1

}


nlat <- 100

nlon <- 100

lat <- seq(-180, 180, length.out = nlat)

lon <- seq(-90, 90, length.out = nlon)

lat <- matrix(rep(lat, nlon), nrow = nlat)

lon <- matrix(rep(lon, each = nlat), nrow = nlat)


LAND_ISO <- c("AUT","BEL","BGR","HRV","CYP","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","IRL",

              "ITA","LVA","LTU","LUX","MLT","NLD","POL","PRT","ROU","SVK","SVN","ESP","SWE","GBR",

              "USA","CHN","KOR","JPN","EGY","ARE","JOR","SAU","AUS","KEN","NGA","BRA")

value <- runif(length(LAND_ISO), 1, 20)

df <- data.frame(LAND_ISO, value)


g <- list(

  projection = list(type = 'orthographic'),

  showland = TRUE,

  landcolor = toRGB("LightGrey"),

  showocean = TRUE,

  oceancolor = toRGB("LightBlue"),

  showlakes = TRUE,

  lakecolor = toRGB("Blue"),

  showrivers = TRUE,

  rivercolor = toRGB("Blue"),

  resolution = 100,

  showcountries = TRUE,

  countrycolor = toRGB("Black"),

  showlon = TRUE,

  loncolor = toRGB("White"),

  showlat = TRUE,

  latcolor = toRGB("White"),

  showcities = TRUE,

  citycolor = toRGB("Red"),

  showmark = TRUE,

  markcolor = toRGB("Green")

)


recruitment_info <- data.frame(Centre = c("CentreA", "CentreB", "CentreC"),

                               Lat = c(51.51770, 52.48947, 51.45451),

                               Long = c(-0.100400, -1.898575, -2.587910),

                               GroupA = c(907, 1910, 4419),

                               GroupB = c(47, 116, 277), stringsAsFactors = TRUE)


recruitment_info <- recruitment_info %>% 

  gather(Group, values, Centre, Lat, Long)


dat <- map_data(map = "world", region = "UK")


fig <- plot_geo(df, type = 'scattergeo', mode = 'lines') 


fig <- fig %>% 

  add_sf(

    data = sf::st_as_sf(maps::map("world", plot = TRUE, fill = TRUE)),

    x = ~ 1.001 * cos(deg2rad(x)) * cos(deg2rad(y)),

    y = ~ 1.001 * sin(deg2rad(x)) * cos(deg2rad(y)),

    z = ~ 1.001 * sin(deg2rad(y)),

    color = I("black"), size = I(1),

    hoverinfo = "skip"

  ) %>%

  add_surface(

    x = cos(deg2rad(lon)) * cos(deg2rad(lat)),

    y = sin(deg2rad(lon)) * cos(deg2rad(lat)),

    z = sin(deg2rad(lat)),

    surfacecolor = matrix(df$value, nrow = nlat, ncol = nlon),

    showscale = TRUE, hoverinfo = "skip",

    contours = list(

      x = list(highlight = TRUE),

      y = list(highlight = TRUE),

      z = list(highlight = TRUE)

    )) %>%

  add_trace(x = df$x, y = df$y, z = df$z, location = ~LAND_ISO,

            line = list(shape = "circle"), showlegend = TRUE,

            hoverinfo = "skip") %>%

  add_trace(

    z = ~value, locations = ~LAND_ISO,

    color = ~value, colors = 'Purples' ) %>%

  add_trace(

    type = "choroplethmapbox",

    geojson = paste(c(

      "https://gist.githubusercontent.com/cpsievert/",

      "7cdcb444fb2670bd2767d349379ae886/raw/",

      "cf5631bfd2e385891bb0a9788a179d7f023bf6c8/", 

      "us-states.json"

    ), collapse = ""),

    locations = row.names(state.x77),

    z = state.x77[, "Population"] / state.x77[, "Area"],

    span = I(0)

  ) %>%

  add_trace(

    type = "choroplethmapbox",

    geojson = paste(c("https://raw.githubusercontent.com/mlampros/DataSets/master/california.geojson"),

                    collapse = ""),

    locations = row.names(state.x77),

    z = state.x77[, "Population"] / state.x77[, "Area"],

    span = I(1)

  ) %>%

  add_segments(x = -cos(15), y = -180 ,xend = -360 ,yend = sin(45)) %>%

  add_segments(x = -100, xend = -50, y = 50, yend = 75) %>%

  layout(geo = g)


fig



댓글(0) 먼댓글(0) 좋아요(0)
좋아요
l 공유하기 l 북마크하기찜하기