Last active
April 17, 2019 15:44
-
-
Save JohnCoene/0742920d08ba00c66a5373aff062b387 to your computer and use it in GitHub Desktop.
how to change the line width based on variables in the data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(echarts4r) | |
| flights <- read.csv( | |
| paste0("https://raw.githubusercontent.com/plotly/datasets/", | |
| "master/2011_february_aa_flight_paths.csv") | |
| ) | |
| flights <- flights %>% | |
| dplyr::mutate(width = scales::rescale(cnt, to = c(0, 5))) | |
| # More icons available with | |
| # echarts.assets | |
| # https://echarts4r-assets.john-coene.com/ | |
| icon <- 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z' | |
| flights %>% | |
| e_charts() %>% | |
| e_geo() %>% | |
| e_lines( | |
| start_lon, | |
| start_lat, | |
| end_lon, | |
| end_lat, | |
| airport1, | |
| airport2, | |
| cnt, | |
| name = "flights", | |
| effect = list( | |
| show = TRUE, | |
| symbol = icon, | |
| trailLength = .1 | |
| ), | |
| lineStyle = list( | |
| curveness = .5, | |
| color = list( | |
| type = "linear", | |
| x = 0, | |
| y = 0, | |
| x2 = 0, | |
| y2 = 1, | |
| colorStops = list( | |
| list( | |
| offset = 0, | |
| color = 'red' | |
| ), | |
| list( | |
| offset = 1, | |
| color = 'blue' | |
| ) | |
| ), | |
| global = FALSE | |
| ) | |
| ) | |
| ) %>% | |
| e_add("lineStyle", width) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(echarts4r) | |
| flights <- read.csv( | |
| paste0("https://raw.githubusercontent.com/plotly/datasets/", | |
| "master/2011_february_aa_flight_paths.csv") | |
| ) | |
| flights <- flights[100:150,] %>% | |
| dplyr::filter(airport1 %in% c('ORD')) %>% ## reduce data to see the pattern | |
| dplyr::mutate(width = scales::rescale(cnt, to = c(0, 7))) | |
| # More icons available with | |
| # echarts.assets | |
| # https://echarts4r-assets.john-coene.com/ | |
| icon <- 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z' | |
| library(echarts4r.maps) | |
| flights %>% | |
| e_charts() %>% | |
| e_geo("USA") %>% | |
| em_map("USA") %>% # sub-national maps | |
| e_lines( | |
| start_lon, | |
| start_lat, | |
| end_lon, | |
| end_lat, | |
| airport1, | |
| airport2, | |
| cnt, | |
| name = "flights", | |
| effect = list( | |
| show = TRUE, | |
| symbol = icon, | |
| trailLength = .1 | |
| ), | |
| lineStyle = list( | |
| curveness = .5, | |
| color = htmlwidgets::JS("new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ | |
| offset: 0, color: '#58B3CC' | |
| }, { | |
| offset: 1, color: '#F58158' | |
| }], false)") | |
| ) | |
| ) %>% | |
| e_add("lineStyle", width) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(echarts4r) | |
| flights <- read.csv( | |
| paste0("https://raw.githubusercontent.com/plotly/datasets/", | |
| "master/2011_february_aa_flight_paths.csv") | |
| ) | |
| flights <- flights %>% | |
| dplyr::mutate(width = scales::rescale(cnt, to = c(0, 5))) | |
| flights %>% | |
| e_charts() %>% | |
| e_geo() %>% | |
| e_lines( | |
| start_lon, | |
| start_lat, | |
| end_lon, | |
| end_lat, | |
| airport1, | |
| airport2, | |
| cnt, | |
| name = "flights" | |
| ) %>% | |
| e_add("lineStyle", width) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment