Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple plot types? #21

Closed
7yl4r opened this issue Sep 7, 2017 · 9 comments
Closed

support multiple plot types? #21

7yl4r opened this issue Sep 7, 2017 · 9 comments

Comments

@7yl4r
Copy link
Member

7yl4r commented Sep 7, 2017

include plotting_function_call column in indicators.csv:

plot_series(title="my title")

raw_html_passthrough or img_wrapper could be functions that could be called too.

@7yl4r
Copy link
Member Author

7yl4r commented Sep 7, 2017

will need to modify modal_plot template

@7yl4r 7yl4r mentioned this issue Sep 13, 2017
@7yl4r
Copy link
Member Author

7yl4r commented Sep 13, 2017

after further discussion with Ben, I believe we do want to expand support for multiple different ways of generating plots and we feel that the best way is to embed R code directly in the csv column. Default behavior will be to use plot_timeseries, so new users can leave the plot_function_call column empty, advanced users can use this column to override the plot_timeseries call.

@reikopm
Copy link
Contributor

reikopm commented Sep 15, 2017

That would work great for me. Jen Brown (MBNMS) wanted a taxonomic structure plot which I implemented in R using a bar graph on seasonal averages over 16 taxonomic groups.

This is what the code looks like:

urlstr='https://raw.githubusercontent.com/reikopm/info-mb/master/prep/data/phytoplankton/efm_taxa_structure_means.csv'
dat <- read.csv(url(urlstr))

library(plotly)

t <- list(
family = "helvetica",
size = 24,
color = 'black')

p1 <- plot_ly(dat, x = ~Season, y = ~asyn, type = 'bar', name = 'Synechococcus',width=2040, height=1080) %>%
add_trace(y = ~arfp, name = 'Red Fluorescing Picoplankton') %>%
add_trace(y = ~aprym, name = 'Haptophyte') %>%
add_trace(y = ~aaflag, name = 'Autotrophic Flagellate') %>%
add_trace(y = ~aadino, name = 'Autotrophic Dinoflagellate') %>%
add_trace(y = ~acryp, name = 'Cryptomonad') %>%
add_trace(y = ~aprasy, name = 'Prasinophyte') %>%
add_trace(y = ~aphaeo, name = 'Phaeocystsis') %>%
add_trace(y = ~apen, name = 'Pennate Diatom') %>%
add_trace(y = ~acen, name = 'Centric Diatom') %>%
add_trace(y = ~ahdino, name = 'Heterotrophic Dinoflagellate') %>%
add_trace(y = ~ahflag, name = 'Heterotrophic Flagellate') %>%
add_trace(y = ~achoano, name = 'Choanoflagellate') %>%
add_trace(y = ~ahcryp, name = 'Leucocryptos') %>%
add_trace(y = ~ahcil, name = 'Heterotrophic Ciliate') %>%
add_trace(y = ~aacil, name = 'Autotrophic Ciliate') %>%
layout(font=t,yaxis = list(title = 'mg C m-3'),barmode = 'stack') %>%
layout(font=t,title = "Q10:Taxonomic Structure", margin = 1)

@bbest
Copy link
Contributor

bbest commented Sep 18, 2017

This looks great @reikopm !

image

I'll try to work this into the framework as a slightly more generic function. Along with seascape plot and multiple time series (eg in/out MPAs) a la:

image

Side note:

@reikopm
Copy link
Contributor

reikopm commented Sep 20, 2017

I just noticed the seasons in the taxonomic bar plot are not ordered. Added this code:
dat$Season <- factor(dat$Season, levels = c("Spring", "Summer", "Fall", "Winter"))

mb_seasonal_taxonomic_structure2

@7yl4r
Copy link
Member Author

7yl4r commented Oct 6, 2017

It looks like we need this functionality to show the seascapes streamgraphs as well.

@bbest : do you have a specific plan for this or would you like me to take a swing at it?

@7yl4r 7yl4r self-assigned this Oct 17, 2017
@bbest
Copy link
Contributor

bbest commented Oct 17, 2017

Hey @reikopm,

Sorry, been focused on the Explorer app. Am discussing this now with @7yl4r and we're considering putting whole functions in the csv, which could then be evaluated. For instance:

txt = "urlstr='https://raw.githubusercontent.com/reikopm/info-mb/master/prep/data/phytoplankton/efm_taxa_structure_means.csv'
dat <- read.csv(url(urlstr))

library(plotly)

t <- list(
family = 'helvetica',
size = 24,
color = 'black')

p1 <- plot_ly(dat, x = ~Season, y = ~asyn, type = 'bar', name = 'Synechococcus',width=2040, height=1080) %>%
add_trace(y = ~arfp, name = 'Red Fluorescing Picoplankton') %>%
add_trace(y = ~aprym, name = 'Haptophyte') %>%
add_trace(y = ~aaflag, name = 'Autotrophic Flagellate') %>%
add_trace(y = ~aadino, name = 'Autotrophic Dinoflagellate') %>%
add_trace(y = ~acryp, name = 'Cryptomonad') %>%
add_trace(y = ~aprasy, name = 'Prasinophyte') %>%
add_trace(y = ~aphaeo, name = 'Phaeocystsis') %>%
add_trace(y = ~apen, name = 'Pennate Diatom') %>%
add_trace(y = ~acen, name = 'Centric Diatom') %>%
add_trace(y = ~ahdino, name = 'Heterotrophic Dinoflagellate') %>%
add_trace(y = ~ahflag, name = 'Heterotrophic Flagellate') %>%
add_trace(y = ~achoano, name = 'Choanoflagellate') %>%
add_trace(y = ~ahcryp, name = 'Leucocryptos') %>%
add_trace(y = ~ahcil, name = 'Heterotrophic Ciliate') %>%
add_trace(y = ~aacil, name = 'Autotrophic Ciliate') %>%
layout(font=t,yaxis = list(title = 'mg C m-3'),barmode = 'stack') %>%
layout(font=t,title = 'Q10:Taxonomic Structure', margin = 1)
print(p1)"

eval(parse(text=txt))

Similarly you could include static images that have a URL like so:

txt = "knitr::include_graphics('./fish_diversity.png')"

eval(parse(text=txt))

Or leaflet marker cluster:

txt = "library(tidyverse)
library(leaflet)

leaflet(quakes) %>% 
  addTiles() %>% 
  addMarkers(
    clusterOptions = markerClusterOptions())"

eval(parse(text=txt))

I am admittedly nervous about any major architectural changes like this though before we do live demos. @7yl4r is going to play with this in a sandbox (ie github branch) to not affect anything else.

@7yl4r
Copy link
Member Author

7yl4r commented Oct 17, 2017

planned options for new column plot_function in plot_indicators.csv:

  1. leave blank to default to plot_timerseries
  2. put your R code directly in the cell. used for short calls to plotting functions. Possible future functions:
    1. png insert plot function using knitter::include_graphics
    2. html insert plot function
    3. streamgraph plotter for eDNA data (above)
    4. maps using leaflet cluster markers or ddgridR
    5. no_plot function for rm error msg in modal with no plots #30 (edit: nevermind, there is a better way to fix that)
  3. file path to R script that creates plot (for longer custom plotters)

@7yl4r
Copy link
Member Author

7yl4r commented Oct 19, 2017

I have implemented 1, 2.i, 2.ii, 2.v, and 3 above; opened new issues for 2.iii (#36) and 2.iv (#35) since they are a bit bigger.

Initially I kept these commits on the multiplots branch, but I tested building info-demo, info-fk, and info-mb and ran into no issues so I have merged the changes into master.

For now the best place to look to figure out how to use all this functionality is at the marinebon/info-demo readme - specifically the lobster section.

@7yl4r 7yl4r closed this as completed Oct 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants