Git Product home page Git Product logo

plotly_book's Introduction

plotly_book's People

Contributors

cpsievert avatar duju211 avatar jbixon13 avatar markroepke avatar ryanatanner avatar sibusiso16 avatar sowla avatar wibeasley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plotly_book's Issues

Use auto_pdf for print version

Setting this in index.Rmd might do the trick

getOption("knitr.graphics.auto_pdf", !knitr::is_html_output())

This could force include_graphics() to use the pdf version of an image in the print version, if it exists.

In ggplotly the legend for size variable is not showing properly

As in the first chart at this page:
https://plotly-book.cpsievert.me/key-frame-animations.html
the one resulting from this code:
data(gapminder, package = "gapminder")
gg <- ggplot(gapminder, aes(gdpPercap, lifeExp, color = continent)) +
geom_point(aes(size = pop, frame = year, ids = country)) +
scale_x_log10()
ggplotly(gg)

The legend for size variable is not visible properly, the text is half cut.
Is there anything to do to see it in full?

Figure 3.1 does not appear

Hi Carson,

Thanks for the plotly book - it's extremely helpful!

I just wanted to point out a small issue: the Figures in Section 3.1 do not seem to render in the book. The code works if I copy it into an RMarkdown file though!

Best,
Rebecca

Add example of animating bars (as segments) to animation chapter

Perhaps similar to some code from @aloy:

# Script accessing country-level population data via Census Bureau
library(idbr)
library(dplyr)
library(purrr)
library(tidyr)

female <- idb1(country = "BE", year = 2018:2050, variables = c("AGE", "NAME", "POP"), sex = "female")
male   <- idb1(country = "BE", year = 2018:2050, variables = c("AGE", "NAME", "POP"), sex = "male")

belgium <- bind_rows(female, male)

make_ids <- function(.data, .order) {
  base_ids <- 1:nrow(.data)
  extra_ids <- if(.order > 0) seq(from = max(base_ids) + 1, to = max(base_ids) + .order)
  ids <- c(extra_ids, base_ids)
  ids[1:101]
}

be_nested <- belgium %>%
  group_by(SEX, time) %>%
  tidyr::nest() %>%
  mutate(order = time - 2018) %>%
  mutate(ids = map2(data, order, .f = make_ids)) 

belgium2 <- be_nested %>%
  select(-order) %>%
  unnest()

plot_ly(belgium2, color = ~factor(SEX), size = I(5), alpha  = 0.5, colors = c("red", "black")) %>%
  add_segments(x = ~POP, xend = 0, y = ~AGE, yend = ~AGE, frame = ~time)

Any chance to backport some of the packages used ?

1st of all, congratulations to @cpsievert for a great and enlightening book.

I'm using the standard variety of R, from the current package of the stable Debian repo. It's still R 3.3.3, while some of the packages in the book, like trelliscopejs demand R 3.4.0, at least.

So, my question is: what about backporting trelliscope to R 3.3.3 ?

Or maybe using only packages compatible while R 3.3.3 ?

While downloading and compiling R 3.4.0 is probably not that difficult, maybe some of your readers are also using versions older than 3.4.0.

Thank you !

Section 1.2.2 Modifying layers refers to a plot with 3 traces, but shows only 1 trace

On arriving at section 1.2.2 Modifying Layers, p was previously assigned as follows:

p <- ggplot(fortify(gold), aes(x, y)) + geom_line()

This section says that there are three traces within the data, however there is only a "0" appearing under data. In contrast, if p is assigned as follows, I see a 0, 1 and 2 which I understand to be the three traces referred to in the section

`p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() + geom_smooth()

plotly_json(p)
`
This is my first look at plotly, so I could be wrong! but otherwise it is not clear ....

Section on figures?

Already have a section on creating figures on plot.ly, but could use a section modifying them?

Mention choroplethmapbox

A much faster alternative to rendering polygons compared to scattermapbox

Could maybe recreate the cartogram examples with style='white-bg'?

Tags for linked_highlighting don't link to anywhere

linked_highlighting is tagged in the following sections (but clicking on 'linked_highlighting' does not link to more information on the topic)

2.1.3.2 Parallel Coordinates
Section 2.3 Bars & Histograms, note 7: This has some interesting applications for linked highlighting as it allows for summary statistics to be computed on-the-fly based on a selection

Add summary/details hooks

As in HTML5 <summary>/<details>. This could provide a light-weight solution to the lack of code-folding.

Figure 2.20 in Section 2.2.1 Using Scatter traces refers to 3 layout options but shows only 1

Custom geographic and mapbox layout options are not displayed when viewing the plotly book on Chrome.

Additionally, when pasting the code onto my computer (using RStudio) the custom geographic layout is blank. For mapbox, I was informed that a token was required (I did not look into this further).
On inspecting the blank plot region for custom geographic layout and hitting the console tab, I see an error "Failed to load resource: Unable to init SSL Context:"

I have just reviewed Plotly issues 356 and 1111 and wondering if it is a problem with working behind a firewall? Although would that also affect viewing the book on Chrome?

2nd edition outline

Why interactive data visualization?

  • Data science workflow
  • Interactivity augments exploration
    • Some historical context and examples (https://talks.cpsievert.me/20180202/#7)
    • "Interactive graphics enable the analyst to pursue follow-up questions" -- Cook & Swayne, GGobi book, p15
    • A case study of US election data
  • GUI and command-line - conflict or synergy?
  • Web-based visualization
    • New capabilites (e.g. easy sharing, portability) brings new set of concerns (e.g., client-server, security, etc)
    • Great tools for expository vis (d3.js, vega, plotly.js)
    • Lack of tools for exploratory vis (i.e. tools for iteration)

The plotly for R ecosystem

  • plotly is a FOSS tool built with plotly.js and htmlwidgets
  • Plotly's cloud services
    • collaboration, point-and-click editing & collaboration
  • Getting started (installation, etc)
  • Two approaches, one object

The ggplotly() toolbox

  • Makes some plots easier to acheive (e.g., geom_hex(), geom_smooth(), etc)
  • Caveats and limitations
  • Learn plotly.js via ggplotly()

The plot_ly() toolbox

  • Scatter traces
  • Maps
  • Bars & histograms
  • 2D frequencies
  • Raster images
  • 3D graphics

Animating views

  • Key frame animations
  • Linking animated views

Arranging multiple views

  • Arranging htmlwidgets
  • Merging plotly objects
  • Navigating many views

Multiple linked views

  • Linking views with shiny
  • Linking views without shiny

Exporting views

  • Saving local HTML files
  • Embedding local HTML files (i.e., iframe, widgetFrame, etc)
  • Using orca() to export to various file formats
  • Using config(p, editable = T) to manually edit charts
  • Exporting manually edited charts
    • Should this just leverage config(p, toImageOptions = ...)? Or provide a way to get at the underlying JSON?

Performance considerations

  • What's in a plotly object?
  • What happens at print-time?
  • Build-time versus render time
  • Build time
    • profvis
  • Render time
    • SVG vs Web-GL rendering
    • Data summary/simplification

Custom JavaScript

  • Motivate through examples
    • Opening hyperlinks
    • Adding annotations in response to direct manipulation

Other ideas

Advanced case studies

plotly extension packages

  • Hmisc, heatmaply, TSstudio, autoplotly

Add example with all the shapes

Like

s <- schema()
x <- grep("-", s$traces$scatter$attributes$marker$symbol$values, value = T)
plot_ly(x = seq_along(x), y = seq_along(x), symbol = I(x), span = I(1), stroke = I("black"), marker = list(size = 30), text = x, hoverinfo = "text")

Section on restoring state from a bookmark?

Sort of like this example, which currently requires plotly/plotly.R#1392

library(shiny)
library(plotly)

ui <- function(req) {
  fluidPage(
    bookmarkButton(),
    plotlyOutput("plot")
  )
}

server <- function(input, output, session) {
  
  output$plot <- renderPlotly({
    plot_ly(economics, x = ~pop, source = "pop_hist")
  })
  
  onRestored(function(state) {
    hist_relayout <- jsonlite::parse_json(
      state$input[["plotly_relayout-pop_hist-input"]]
    )
    xrng <- as.numeric(hist_relayout[c("xaxis.range[0]", "xaxis.range[1]")])
    
    if (length(xrng)) {
      plotlyProxy("plot") %>% 
        plotlyProxyInvoke("relayout", list(xaxis = list(range = xrng)))
    }
  })
}

shinyApp(ui, server, enableBookmarking = "url")

2.6 Other 3D plots

"the x and y attributes do not have to be provided, but if they are, the length of x should match the number of rows in the matrix and y should match the number of columns."

The statement is not correct. It's exactly the opposite: the length of x should match the number of columns in the matrix and y should match the number of rows. (i agree that plotly is bit weird in this regard.)

x <- seq_len(ncol(volcano)) + 100
y <- seq_len(nrow(volcano)) + 500
plot_ly() %>% add_surface(x = ~x, y = ~y, z = ~volcano)

Problem with linked brushing

(not sure this is the right place for this comment. If this is not, I apologize).
I have a caveat with the example of section
"4.2.3 Linking with other htmlwidgets"
The example seems dependent upon
install_github("rstudio/leaflet#346")
otherwise, if I just install
install_github("rstudio/leaflet")
I get blue color for points on the right map when selecting on the left scatterplot (where points are red or
the selected color), which is inconvenient as selected points cannot be identified on the map.
As this type of linked brushing is very important for me, I would like to know if this code will be
valid for future standard releases of leaflet: sticking to #346 might not be possible in the future or interfere with newer improvements.
Thanks

List of FAQs?

e.g.,

  • More cohesive explanation of updatemenus than https://plot.ly/r/dropdowns/
    • Perhaps draw connections to plotlyProxy()?
  • How to add margin(s) to a plot?
  • How to customize axes (e.g., titles, tickvals/ticktext, etc)?
  • Why does my line plot appear blank (i.e., malformed group definition)?
  • Why is my plot being sluggish
    • Point to SVG vs WebGL
  • Why is my plot's file size so big?
    • Point to partial_bundle()
  • How can a plotly plot from graying-out in shiny?
    • Point to shiny performance section

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.