Coder Social home page Coder Social logo

ggplot2_workshop's Introduction

Drawing Anything with ggplot2

Workshop material

This repository collects material for a ~4 hour workshop first taught at celebRation2020 in Copenhagen

Workshop Video on YouTube

ggplot2_workshop's People

Contributors

jananiravi avatar thomasp85 avatar tkragholm 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ggplot2_workshop's Issues

Error for scale_x_continuous(expand = c(0, NA))

I am trying one example in the slides and get an error: Error in if (zero_range(as.numeric(limits))).

When I add scale_x_continuous(expand = c(0, NA)) in the code chunk.

mpg %>% 
    group_by(year, class) %>% 
    count() %>% 
    ggplot() +
    aes(x = n, y = class) + 
    geom_col() +
    labs(
        title = "Number of car models per class",
        caption = "source: http:!/fueleconomy.gov",
        x = NULL,
        y = NULL
    ) +
    scale_x_continuous(expand = c(0, NA)) +
    theme_minimal() +
    theme(
        text = element_text('Avenir Next Condensed'),
        strip.text = element_text(face = 'bold',
                                  hjust = 0),
        plot.caption = element_text(face = 'italic'),
        panel.grid.major = element_line('white',
                                        size = 0.5),
        panel.grid.minor = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.ontop = TRUE
    ) + 
    facet_wrap( ~ year) + 
    coord_flip()
"SI"
#> [1] "SI"

Created on 2020-03-02 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                                              
#>  version  R version 3.6.0 (2019-04-26)                       
#>  os       Windows 7 x64 SP 1                                 
#>  system   x86_64, mingw32                                    
#>  ui       RTerm                                              
#>  language (EN)                                               
#>  collate  Chinese (Simplified)_People's Republic of China.936
#>  ctype    Chinese (Simplified)_People's Republic of China.936
#>  tz       Asia/Taipei                                        
#>  date     2020-03-02                                         
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version    date       lib source                        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.2)                
#>  backports     1.1.5      2019-10-02 [1] CRAN (R 3.6.1)                
#>  callr         3.2.0      2019-03-15 [1] CRAN (R 3.6.0)                
#>  cli           2.0.1      2020-01-08 [1] CRAN (R 3.6.2)                
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)                
#>  devtools      2.1.0      2019-07-06 [1] CRAN (R 3.6.1)                
#>  digest        0.6.19     2019-05-20 [1] CRAN (R 3.6.0)                
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)                
#>  fansi         0.4.0      2018-10-05 [1] CRAN (R 3.6.0)                
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)                
#>  htmltools     0.4.0      2019-10-04 [1] CRAN (R 3.6.1)                
#>  knitr         1.27       2020-01-16 [1] CRAN (R 3.6.2)                
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.1)                
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.1)                
#>  pkgbuild      1.0.3      2019-03-20 [1] CRAN (R 3.6.1)                
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.1)                
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.0)                
#>  processx      3.3.1      2019-05-08 [1] CRAN (R 3.6.0)                
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.2)                
#>  Rcpp          1.0.3      2019-11-08 [1] CRAN (R 3.6.2)                
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.1)                
#>  rlang         0.4.4      2020-01-28 [1] CRAN (R 3.6.0)                
#>  rmarkdown     2.1        2020-01-20 [1] CRAN (R 3.6.2)                
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)                
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                
#>  usethis       1.5.1.9000 2020-02-04 [1] Github (r-lib/usethis@e7c1f17)
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                
#>  xfun          0.8        2019-06-25 [1] CRAN (R 3.6.1)                
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                
#> 
#> [1] C:/Program Files/R/R-3.6.0/library

geom_contour

Hi Thomas,
More a question than an issue; In fact I am using ggplot to contour sea level pressure using geom_contour and can plot values without problem. Now I need to plot a specific value (here 1015) as bold or thicker contour than the others and wonder if you see a way to do it?
below the command I use:
geom_contour2(data = synclas_gather_df, aes(x=x,y=y,z=value), binwidth = 2, color = "black") +
scale_fill_gradientn(colours = colorRamps::matlab.like2(100), name = "hPa",breaks=0:5) +
scale_colour_gradient(guide = 'none') + facet_wrap(~key, ncol = 4) +

The interval I have here is 2, so I have let's say 1010, 1012, 1014, 1016 etc. Now how to skip the 1014 and replace it with 1015?
Thank you for the noce tutorail

Great tutorial! quick question on after_stat.

ggplot(mpg) +

Just trying to stretch the new functionalities of after_stat. It is already much clear than its predecessors. Yet maybe I am mistaken, after_stat currently do not seem to be able to take named functions. I tried to look into the error message and source code but tidy evaluation is a bit hard for me to pin down. Is that a current limitation? Wonder if I can help?

library(ggplot2)
percentage <- function() count / sum(count)
ggplot(mpg) + 
  geom_bar(aes(x = class, y = after_stat((function() count / sum(count))())))

ggplot(mpg) + 
  geom_bar(aes(x = class, y = after_stat((percentage)())))
#> Error in (percentage)(): object 'count' not found

Created on 2020-04-04 by the reprex package (v0.3.0)

library(ggplot2)
library(rlang)
percentage <- function() {
  count <- enquo(count)
  expr(!!count / sum(!!count)) 
}

ggplot(mpg) + 
  geom_bar(aes(x = class, y = after_stat(eval_tidy(percentage()))))
#> Error in (function (x) : object 'count' not found

Created on 2020-04-04 by the reprex package (v0.3.0)

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.