View it here -- http://cpsievert.github.io/plotly_book
$ Rscript -e "devtools::install_github('cpsievert/plotly_book')"
$ make
plotly for R book
Home Page: https://plotly-r.com
License: Other
View it here -- http://cpsievert.github.io/plotly_book
$ Rscript -e "devtools::install_github('cpsievert/plotly_book')"
$ make
At least for the online version, it'd be nice to have gifs that link to the interactive.
For the print version, it prob make most sense to explicitly write the hyperlink in the figure caption
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.
And ideally already have plotly loaded so folks can just copy/paste examples to get the interactive.
Mention this instance in the initial overview.
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?
To acknowledge all contributors
Lots of reviewers said these chapters are "not complete"
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
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)
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 !
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 ....
Already have a section on creating figures on plot.ly, but could use a section modifying them?
A much faster alternative to rendering polygons compared to scattermapbox
Could maybe recreate the cartogram examples with style='white-bg'
?
Add an example of drilling down in a single view, like https://edgarruiz.shinyapps.io/db-dashboard/
Also, now that we have sunburst, would be nice to mention this 'native' drill-down ability, and how it can be linked to other views
Based on discussion in plotly/plotly.R#1441
Arrow turns to crosshairs when entering barplot
Perhaps extending the freqpoly example in the intro to ggplotly
This section is currently written for an academic audience -- it should have less theory and more practice (i.e., many more examples!)
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
As in HTML5 <summary>
/<details>
. This could provide a light-weight solution to the lack of code-folding.
Also unable to create from code
Perhaps make this note in polygons section and make a nod to it in mapping
Also, make sure all the good ideas from here are in the book https://blog.cpsievert.me/2018/03/30/visualizing-geo-spatial-data-with-sf-and-plotly/
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?
Using albersusa, extending the current example
Folks seem to want this
So that printed links can be ported to another location, if need be
404
e.g. ch 4.2.3
I'm using plotly 4.5.6.9000
ggplotly()
toolboxgeom_hex()
, geom_smooth()
, etc)plotly.js
via ggplotly()
plot_ly()
toolboxorca()
to export to various file formatsconfig(p, editable = T)
to manually edit chartsconfig(p, toImageOptions = ...)
? Or provide a way to get at the underlying JSON?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")
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")
"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)
If screenshots are needed, put them in images
e.g., what is a trace? what is a figure?
(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
At least for the static plots on the website
This is very minor, but when I copy/paste in Windows some of the code examples give an error since โ
is used instead of "
.
Currently gifs autoplay, which can be quite distracting and annoying for longer gifs if you want to revisit a particular section
One option is to add play/pause to gifs with http://rubentd.com/gifplayer/
Assuming we can get Figure numbering working, embedding vimeos might be a better option. Note that you can embed without the cruft with https://player.vimeo.com/video/257149623?title=0&byline=0&portrait=0
e.g.,
plotlyProxy()
?What software you are using to create your animated gifs?
It should take more time to build the core concepts, like http://bit.ly/jj-shiny-day does
Also, take advantage of plotly/plotly.R#1655, when fixed
Works fine locally, but apparently not on shinyapps
Namely the examples towards the end here https://blog.cpsievert.me/2018/01/30/learning-improving-ggplotly-geom-sf/
Hey there,
I just skimmed over your map chapters, really interesting! And I know that you focus on plotly but I would suggest to at least mention the popular and powerful packages mapview (https://github.com/r-spatial/mapview) and tmap (https://github.com/mtennekes/tmap) when it comes to interactive mapping in R.
Expand on the current section to include:
htmlwidgets::onRender()
) (includes limitations -- does it work in shiny?)Maybe take an example from ?scale_color_gradient2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.