Giter Site home page Giter Site logo

ggcharts's Introduction

Hi there 👋

Some facts about myself:

me <- list(
  name = "Neitmann",
  first_name = "Thomas",
  occupation = "Associate Director, Data Science",
  employer = "Denali Therapeutics",
  favorite_programming_language = "R",
  my_r_packages = c("admiral", "ggcharts", "mdthemes"),
  blog = "https://thomasadventure.blog/"
)

Here are my top 5 most popular R blog posts:

ggcharts's People

Contributors

indrajeetpatil avatar sjlva avatar thomas-neitmann 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

ggcharts's Issues

Error in (function (el, elname) :

When I try to use ggcharts, encounter Error

here is the code and error message:
base_plot <- ggplot(mtcars, aes(hp, mpg)) + geom_point(color = "gray")
p1 <- base_plot + theme_ggcharts()

Error in (function (el, elname) :
"plot.title.position" is not a valid theme element name.

bar_chart() sorts when sort = FALSE

library(ggcharts)
data(biomedicalrevenue)
revenue_2018 <- biomedicalrevenue[biomedicalrevenue$year == 2018, ]
bar_chart(revenue_2018[c(3, 9, 2, 20, 13), ], company, revenue, sort = FALSE)

image

Modify bar_chart {ggcharts} Example

Modify/Change bar_chartexample from:
biomedicalrevenue %>%
filter(year == 2018) %>%
bar_chart(company, year, limit = 10)
to a potentially more pleasing:
...
bar_chart(company, revenue, limit = 10)

Legend pops up when changing theme

Currently, the highlight feature is implement via scale_fill_manual(). This has the consequence that when changing the theme a legend pops up. Implementing the highlight feature via scall_fill_identity() should fix this.

plot <- biomedicalrevenue %>%
  filter(year == 2014) %>%
  bar_chart(company, revenue, limit = 10, highlight = "Sanofi") %>%
  print()

image

plot + theme_classic()

image

Display "other" in chart

When using the threshold argument of bar_chart() and lollipop_chart() it would be nice to have an option to display a bar/lollipop at the bottom that sums up the values of all categories falling below the threshold.

data <- data.frame(
  cat = letters[1:10],
  val = c(4, 5, 2, 1, 22, 12, 32, 11, 5, 1),
  stringsAsFactors = FALSE
)

reorder_other <- function(x, by) {
  x2 <- x[x != "other"]
  by2 <- by[x != "other"]
  levels <- c("other", x2[order(by2)]) %>% print()
  ordered(x, levels = levels)
}

p <- data %>%
  mutate(cat2 = ifelse(val > 4, cat, "other")) %>%
  group_by(cat2) %>%
  summarise(val = sum(val)) %>%
  ungroup() %>%
  mutate(cat2 = reorder_other(cat2, val)) %>%
  bar_chart(cat2, val, sort = FALSE) %>%
  print()

image

In addition an automatic footnote should be generated.

p + labs(caption = "'Other' contains all categories with a value less than or equal to 4.")

image

Dynamic color for charts using fill

Do you have examples with the usage for fill?

I have the following code:

items %>%
  dplyr::group_by(state) %>%
  dplyr::summarise(n = sum(n)) %>%
  dplyr::mutate(col = ifelse(n > 50, "#1F77B4", "#2CA02C")) %>%
  ggcharts::bar_chart(
    state, 
    n, 
    limit = 15,
    fill = col
  )

That produces the following plot:

If I add + scale_fill_identity() it then produces:

So I wonder what's the correct usage when specifying the fill attribute for ggplot.

Refactor `diverging_*_chart()` functions

Although diverging_bar_chart() and diverging_lollipop_chart() have almost the same code, they currently live separated in two files. That way whenever something needs to be updated, it has to been done in both files which is cumbersome and error prone.

To mitigate this, create a diverging_chart() function that is called internally by diverging_bar_chart() and diverging_lollipop_chart(). This function should do all the work.

A simple sequence of the data frame should be sufficient to achieve the order sequence rather then pulling out the variable and sequencing on it.

I noticed that in the pyramid_chart function if there is no sorting order then you create a sequence vector and assign it to order.
order <- data %>% dplyr::pull(!!x) %>% seq_along()
It would be a little efficient to just to use order <- 1:nrow(data).
Is there a specific reason why you do this by pulling the variable out?
I get that for creating the limit you have to pull the y column out but I don't think you'd need to do that for order.

pyramid_chart lost half tag

Hi guys,
I really appreciate your ggcharts package.
But a bug occur to me.
When I try pyramid_chart with geom_text(), it lost the left half tagg.

Here is the code:
data(popch) options(scipen = 999) pyramid_chart(popch, age, pop, sex, xlab = "Population", title = "Switzerland 2020") + geom_text(aes(label=round(pop/10000,2)))

Add `column_chart()` function

The column_chart() function should be a wrapper of bar_chart() with horizontal = FALSE and sort = !is.numeric(x) as default.

Adjust default theme

Adjust the default theme to include a proper x axis line with ticks, greater font size and possibly a different default font. Think about removing all grid lines.

Remove the tidytext dependency

Currently, {ggcharts} depends on {tidytext} because it uses reorder_within() and scale_x_reordered(). Both functions are super short and require only the {base} package and {ggplot2}, whereas the rest of {tidytext} has lots of dependencies. Integrate the two functions into {ggcharts} source code to avoid having to install all these dependencies.

Highlight Vignette

Create a vignette showcasing the highlight feature of bar_chart() mad lollipop_chart() .

Standard evaluation functions

All functions currently use non-standard evaluation which is great for interactive use but IMO clumsy to program with. Having functions that accepts strings as arguments could come in very handy in {shiny} apps.

Double x axis labels when sort = FALSE and horizontal = FALSE

When calling bar_chart() with sort = FALSE and horizontal = FALSE each x axis label appears twice in the plot:

library(dplyr)
library(ggcharts)
data(biomedicalrevenue)

biomedicalrevenue %>%
  filter(company %in% c("Roche", "Novartis")) %>%
  bar_chart(year, revenue, facet = company, sort = FALSE, horizontal = FALSE)

image

When horizontal = TRUE this does not occur:

biomedicalrevenue %>%
  filter(company %in% c("Roche", "Novartis")) %>%
  bar_chart(year, revenue, facet = company, sort = FALSE, horizontal = FALSE)

image

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.