Skip to content

Plot Builder Plan

Ian Fellows edited this page Mar 9, 2019 · 8 revisions

TODO

Requirements

Below are some plots to keep in mind. The interface does not have to be, and perhaps should not be, a direct mirror of the code.

# Novice: Make a histogram (numeric x)
(
  ggplot(mtcars, aes(mpg)) +
  geom_histogram(bins=20) +
  theme_bw()
) %>% ggplotly()

# Novice: Make a bar plot (categorical x)
(
  ggplot(mtcars, aes(cyl)) +
    geom_bar() +
    theme_bw()
) %>% ggplotly()

# Novice: Make a single boxplot (numeric y)
(
  ggplot(mtcars, aes(mpg, x="")) +
    geom_boxplot() +
    xlab("") +
    theme_bw()
) %>% ggplotly()

# Novice: Make a bar plot (categorical y)

(
  mtcars %>% 
    group_by(cyl) %>% 
    summarise( count= n()) %>% 
    ggplot(aes(x=count, y=cyl)) +
    geom_point(size=2) +
    geom_errorbarh(aes(xmax=count), xmin=0, height=0) +
    theme_bw()
) %>% ggplotly()

# Novice: Make a statter plot (numeric x and y)
(
  ggplot(mtcars, aes(wt, mpg)) + 
    geom_point() + 
    theme_bw()
) %>% ggplotly()

# Novice: with labels
(
  ggplot(mtcars, aes(wt, mpg)) + 
    geom_point() + 
    ggtitle("Scatter") +
    xlab("weight") + 
    ylab("MPG") + 
    theme_bw()
) %>% ggplotly()


# Novice: Make a box plot (categorical x numeric y)
(
  ggplot(diamonds, aes(cut, price)) + 
    geom_boxplot() + 
    theme_bw()
) %>% ggplotly()

# Novice: Make a multiple histogram plot (numeric x categorical y)
library(ggridges)
#( #doesn't yet work with plotly
  ggplot(diamonds, aes(price, cut)) + 
    stat_binline(bins = 50, scale = .7, draw_baseline = FALSE) +
    theme_ridges()
#) %>% ggplotly()

# Novice: Make a grid plot (categorical x categorical y)
(
  ggplot(diamonds, aes(x=color, y=cut, fill=stat(count))) + 
    stat_bin2d() + 
    scale_fill_gradient2() + 
    theme_bw()
) %>% ggplotly()



# Moderate: with colors and line
(
  ggplot(mtcars, aes(wt, mpg, color=factor(cyl))) + 
    geom_point() + 
    geom_smooth() + 
    theme_bw()
) %>% ggplotly()

# Moderate: faceting
(
  ggplot(mtcars, aes(wt, mpg)) + 
    geom_point() + 
    geom_smooth() + 
    facet_wrap(~cyl) + 
    theme_bw()
) %>% ggplotly()


library(gapminder)
# Advanced: Animation + log scale axis
(
  ggplot(gapminder, aes(gdpPercap, lifeExp, color = continent)) +
    geom_point(aes(size = pop, frame = year, ids = country)) +
    scale_x_log10() + 
    theme_bw()
) %>% ggplotly()



# Advanced: Violin and Summary
(
  ggplot(mtcars, aes(factor(cyl), mpg)) + 
    geom_violin(color="white",fill="grey90") +
    stat_summary(fun.data=function(x) data.frame(
      y=mean(x, na.rm=TRUE), 
      ymin=mean(x, na.rm=TRUE)-sd(x,na.rm=TRUE), 
      ymax=mean(x, na.rm=TRUE)+sd(x,na.rm=TRUE)),
      color="red") +
    coord_flip() +
    theme_bw()
) %>% ggplotly()

Designs

Clone this wiki locally