library(plotly)

library(dplyr)

library(rearrr)

library(rgdal)

library(sp)

library(sf)

library(tidyr)

library(spreadr)

library(spatstat.sparse)

library(REdaS)


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

co  



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

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

df[,2] <- log(df[,2])

df



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

co[,2] <- log(co[,2])


co <- data.frame(

  "x" = runif(20),

  "y" = runif(20)

)

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

elev


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

qk

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

qk[,2] <- log(qk[,2])



deg2rad <- function(deg) {

  (deg * pi) / (180)

}


deg2rad(sin(45))



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)

pg <- list(nlat,nlon)

str(pg)

table(list = c(nlat,nlon))


#

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)



#

LAND_ISO <- c("USA")

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

df <- data.frame(LAND_ISO, value)


#

LAND_ISO <- c("KOR","JPN","CHN")

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

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")

)


x <- rnorm(177, mean = 5)

y <- rnorm(177, mean = -5)

z <- rnorm(177, mean = 5 )

x <- c(1:177)

y <- c(1:177)

z <- c(1:177)

df <- data.frame(x,y,z)


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 <- recruitment_info %>% 

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

recruitment_info


table(recruitment_info)

str(recruitment_info)


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

dat


##

table2%>%spread(key= 1,value = Group)



#1

fig <- plot_geo(bt)


fig1 <- fig %>% layout(geo = g)%>%

  add_trace(bt,y = trace_1, name = 'trace 0', mode = 'lines')%>%

  add_segments(x = cos(0), y = 180 ,xend = 360 ,yend = tan(89))%>%

  add_segments(x = sin(45), y = cos(720),xend = 180,yend = tan(89))

fig2 <- fig %>% layout(geo = g)%>%

  add_trace(bt,y = trace_2, name = 'trace 1', mode = 'lines')%>%

  add_segments(x = 180, y = cos(0),xend = 0,yend = tan(89))


print(fig1,fig2)



#2


fig <- plot_geo(type = 'scattergeo',group = bt,

                mode = "lines")%>%

  

  add_trace( colors = 'Greens',locations = 'world')%>%

  

  add_markers(x = 0,y = 90)%>%

  add_markers(x = 127, y = 37)%>%

  add_markers(x = 0, y = 0)%>%

  add_markers(x = 0, y = 51)%>%

  add_segments(x = sin(45), cos(45),xend = cos(45),yend = sin(45))%>%

  add_segments(x = 127, y = 37 ,xend = -360 ,yend = sin(45))%>%

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

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

  add_segments(x = -cos(90), y = -180 ,xend = -360 ,yend = tan(89))%>%

  add_segments(x = 0, y = -60 ,xend = -40 ,yend = tan(45))%>%

  add_segments(x = cos(90), y = 180 ,xend = 360 ,yend = tan(89))%>%

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

  add_segments(x = 0, y = 60 ,xend = 40 ,yend = tan(45))%>%

  add_segments(x = 0,y = 0, xend = 180, yend = tan(60))%>%

  add_segments(x = tan(45),y = 180 , xend = 90, yend = tan(15))%>%

  add_segments(x = 0,y = 90 , xend = 90, yend = tan(15))%>%

  add_segments(x = 0,y = sin(60) , xend = sin(60), yend = 0)%>%

  add_segments(x = sin(45),y = 0 , xend = 0, yend = -sin(45))%>%

  add_segments(x = -sin(45),y = 0 , xend = 0, yend = -sin(45))%>%

  add_segments(x = 0,y = 0 , xend = -sin(45), yend = -sin(45))%>%

  add_segments(x = 0,y = 0 , xend = -sin(45), yend = tan(45))%>%

  add_segments(x = 90,y = 90 , xend = -sin(45), yend = tan(45))%>%

  

  add_trace(

    x = ~nlon,y = ~nlat,group = bt,

    line = list(shape = "spline"),

    showlegend = TRUE,

    hoverinfo = "y") %>%

  add_trace(bt,y = trace_6, name = 'trace 6', mode = 'lines')%>%

  add_trace(bt,y = trace_7, name = 'trace 7', mode = 'lines')%>%

  

  

  

  layout( geo = g)


print(fig)



###3


fig <- plot_geo(dat,type = 'scattergeo', mode = 'markers')%>%

  

  add_trace( colors = 'Greens',locations = 'uk')%>%

  add_trace(recruitment_info,

            group_by = "Centre",

            line = list(shape = "spline"),

            showlegend = TRUE,

            hoverinfo = "region")%>%

  add_markers(y = 51, x = 0)%>%

  

  layout( geo = g )



fig





#4

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

                lat = c(0,45,90,-45,0), lon = c(0,-45,-90,45,0))

fig <- fig %>% 

  add_surface(bt,

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

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

              z = sin(deg2rad(lat)),

              surfacecolor = matrix(bt, nrow = nlat, ncol = nlon),

              showscale = TRUE, hoverinfo = c("lon","lat"),

              contours = list(

                x = list(highlight = TRUE),

                y = list(highlight = TRUE),

                z = list(highlight = TRUE)

              ))%>%

  

  

  add_trace(bt,

            group = NULL,

            line = list(shape = "circle"),

            showlegend = TRUE,

            hoverinfo = "skip")%>%

  

  layout(geo = g)

fig





#5

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


fig <- fig %>% 

  add_lines(y = list(0,90,0,-90,90), x = list(0,-90,0,90,-90))%>%

  add_lines(y = list(90,0,-90,0), x = list(-90,0,90,0))%>%

  add_lines(x = list(0,45,90,-45,0,45,90), y = list(0,-45,-90,45,0,-45,-90))%>%

  add_trace(bt,x = x, y = y,

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

            hoverinfo = "skip")%>% 

  

  

  layout(geo = g)


fig


bbox(fig)





#6

fig <- plot_geo(df,type = 'scattergeo', mode = 'markers', fill = TRUE)


fig <- fig %>% 

  

  add_trace(x = ~lon, y = ~lat,

            line = list(shape = "circle"),showlegend = TRUE,hoverinfo = list("lon","lat","alt"))%>% 

  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, nrow = nlat, ncol = nlon),

    showscale = TRUE, hoverinfo = "skip",

    contours = list(

      x = list(highlight = TRUE),

      y = list(highlight = TRUE),

      z = list(highlight = TRUE)

    ))%>%          

  

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

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

  add_segments(x = -cos(90), y = -180 ,xend = -360 ,yend = tan(89))%>%

  #add_segments(x = sin(45), cos(45),xend = cos(45),yend = sin(45))%>%

  #add_segments(x = 90,y = 90 , xend = -sin(45), yend = tan(45))%>%

  #add_segments(x = tan(45),y = 180 , xend = 90, yend = tan(15))%>%

  #add_segments(x = 90,y = 90 , xend = -sin(45), yend = tan(45))%>%

  #add_segments(x = 0,y = 90 , xend = 90, yend = tan(15))%>%

  

  layout( geo = g, annotation = NULL)


print(fig)





##7

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, 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 = x, y = y, z = 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



#8


fig <- plot_geo(df) %>%

  add_trace(z = ~COUNTRY., color = ~CODE, colors = 'Reds',

            text = ~COUNTRY, locations = ~CODE) %>%

  add_trace(df,

            group_by = "CODE",

            line = list(shape = "markers"),

            showlegend = TRUE,

            hoverinfo = "skip")%>%

  colorbar(title = 'GDP (log)') %>%

  layout(title = '', geo = g)

print(fig)





#9

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


fig <- plot_geo(co)%>%  

  add_trace(z = ~Population, color = ~Population, colors = 'Reds',

            text = ~Region, locations = ~Country) %>%

  colorbar(title = 'Population') %>%

  

  

  

  layout( geo = g )



fig





#10

fig <- plot_geo(qk,type = 'scattergeo', mode = 'markers')%>%

  

  add_trace(z = ~impact.magnitude, color = ~location.name, colors = 'Reds',

            text = ~location.depth, locations = c(~location.longitude,~location.latitude)) %>%

  colorbar(title = 'impact.magnitude') %>%

  

  add_trace(qk,

            group_by = "impact.magnitude",

            line = list(shape = "markers"),

            showlegend = TRUE,

            hoverinfo = "skip")%>%

  

  layout( geo = g )



fig



test <- read.OGR("https://raw.githubusercontent.com/mlampros/DataSets/master/california.geojson")

test


rt <- geojson_read("https://opendata.arcgis.com/datasets/772f3621fa354ec9abf3ba33f3ace59e_0.geojson")

rt                    



file <- system.file("examples", "california.geojson", package = "geojsonio")

(out <- geojson_read(file))

rt <- geojson_read("https://opendata.arcgis.com/datasets/772f3621fa354ec9abf3ba33f3ace59e_0.geojson")

rt                    )



library("rjson")

json_file <- "https://gist.githubusercontent.com/cpsievert/"

"7cdcb444fb2670bd2767d349379ae886/raw/"

"cf5631bfd2e385891bb0a9788a179d7f023bf6c8/" 

"us-states.json"

json_data <- fromJSON(paste(readLines(json_file), collapse=""))

json_data

str(json_data)



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