Comments (11)
Hi,
data must NOT be JSON. Sorry, I have to update the docs showing how to use R data objects.
You just need to pass the column names for lat and lng via get_position
R function, e. g.
scatterplot:
deckgl(latitude = -24.655, longitude = 176.9, zoom = 4) %>%
add_scatterplot_layer(
data = quakes,
getPosition = get_position("lat", "long"),
getRadius = JS("d => d.mag * 100"),
radiusScale = 60,
getColor = JS("d => [Math.sqrt(d.depth) * 20, 130, 10]")
)
icon:
deckgl(latitude = -24.655, longitude = 176.9, zoom = 4) %>%
add_icon_layer(
data = quakes,
getPosition = get_position("lat", "long"),
getSize = get_property("mag"),
getColor = JS("d => [Math.sqrt(d.depth) * 20, 130, 10]")
)
from deckgl.
Another example using data from the deckgl
package
sample_data <- deckgl::bart_stations
sample_data$radius <- sqrt(sample_data$exits)
properties <- list(
getPosition = get_position("lat", "lng"),
getRadius = get_property("radius"),
radiusScale = 6,
getColor = c(255, 140, 20)
)
deck <- deckgl(zoom = 10.5, pitch = 35) %>%
add_scatterplot_layer(data = sample_data, properties = properties) %>%
add_mapbox_basemap()
if (interactive()) deck
from deckgl.
from deckgl.
It really helped
Many thanks @crazycapivara
from deckgl.
Another example using data from the
deckgl
packagesample_data <- deckgl::bart_stations sample_data$radius <- sqrt(sample_data$exits) properties <- list( getPosition = get_position("lat", "lng"), getRadius = get_property("radius"), radiusScale = 6, getColor = c(255, 140, 20) ) deck <- deckgl(zoom = 10.5, pitch = 35) %>% add_scatterplot_layer(data = sample_data, properties = properties) %>% add_mapbox_basemap() if (interactive()) deck
hi @crazycapivara
Some other questions:
head(a)
lng lat
1 116.71148 39.434895
2 116.71148 39.434895
3 116.71148 39.434895
4 116.71144 39.435100
5 116.71144 39.435060
6 116.71140 39.435090
How to get path, Is get_position still valid?
when I try that ,I get nothing
code as follow:
properties <- list(
pickable = TRUE,
widthScale = 20,
widthMinPixels = 2,
getPosition = get_position("lat", "lng"),
getColor = c(255, 140, 20),
getWidth = 5
,getTooltip = get_property("pd")
)
deck <- deckgl(latitude = 38.38687967,longitude = 114.42064498,pitch = 25, zoom = 5.5) %>%
add_path_layer(data = a, properties = properties) %>%
add_mapbox_basemap()
if (interactive()) deck
from deckgl.
properties <- list(
pickable = TRUE,
widthScale = 20,
widthMinPixels = 2,
getPosition = get_position("lat", "lng"),
getColor = c(255, 140, 20),
getWidth = 5
)
deck <- deckgl(latitude = 38.38687967,longitude = 114.42064498,pitch = 25, zoom = 5.5) %>%
add_path_layer(data = a, properties = properties) %>%
add_mapbox_basemap()
if (interactive()) deck
from deckgl.
Hi @liygzting,
you need to use the right data format as specified in deckgl-path-layer-api-reference:
// Data format:
[
{
path: [[-122.4, 37.7], [-122.5, 37.8], [-122.6, 37.85]],
name: 'Richmond - Millbrae',
color: [255, 0, 0]
},
...
]
Furthermore, you need to use the getPath
property as shown in the docs.
So, you need a list column in your data.frame
containing the coords of the path(es).
Here is an example using the bart_stations
data set:
coords <- deckgl::bart_stations[, c("lng", "lat")] %>%
as.matrix()
data <- tibble::tibble(
tooltip = "Bart Stations",
path = list(coords)
)
# Check, if your data format is correct
jsonlite::toJSON(data) %>% print()
properties <- list(
pickable = TRUE,
widthScale = 20,
widthMinPixels = 2,
getPath = get_property("path"),
getColor = c(250, 140, 20),
getWidth = 5,
getTooltip = get_property("tooltip")
)
deckgl(zoom = 9, pickingRadius = 20) %>%
add_path_layer(data = data, properties = properties) %>%
add_icon_layer(
data = bart_stations,
getPosition = get_position("lat", "lng"),
getColor = c(10, 140, 50),
getTooltip = get_property("name")
)
from deckgl.
Alternatively, you can create the data using a list of lists:
coords <- deckgl::bart_stations[, c("lng", "lat")] %>%
as.matrix()
data <- list(
list(
tooltip = "Bart Stations",
path = coords
)
)
from deckgl.
thanks @crazycapivara ,
for path , scatter,icon or grid etc, I change data to tibble not dataframe so that i can plot most of layer.
Does that mean you can just use this?
Or is there anything else to notice?
from deckgl.
Nope, you can use a data.frame
aswell. A tibble
is just a variant and often more comfortable to handle. That's why I prefer it, e. g. when using list
columns. Here is how to create a data.frame
with list
column which works fine:
# coords same as above
df <- data.frame(
tooltip = "Bart Stations",
path = I(list(coords))
)
For all layers expecting point data it's fine to have a data.frame
with lat
and lng
columns.
It is planned to support sf
objects, see #81.
from deckgl.
thanks @crazycapivara
It really makes sense
Since you told me this good method, I decided to start using tibble too.
from deckgl.
Related Issues (20)
- update view state HOT 1
- Syntactic sugar section
- Move /inst/examples to /examples
- Rename first parameter in widegt function from deckgl to deck
- Add shiny example to shiny-bindungs in r-docs
- sf layers aren't rendering HOT 5
- Map not rendering HOT 1
- Adding terrain layer HOT 2
- deck gl layers toggle HOT 2
- Highlight Polygons HOT 1
- Lighting effects for R deckgl HOT 1
- Change view from MapView to OrthographicView
- trips Layer HOT 1
- OnClick not working HOT 1
- removing old add_legend in shiny app HOT 3
- Updating deckgl map in shiny removes previous layer HOT 1
- It is possible that Heatmap doesn't work? HOT 2
- Rendering multiple maps in a Quarto doc creates issue with hovering and tooltips HOT 1
- Rendering Rasters
- FlytoInterpolator
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deckgl.