davidhodge931 / ggblanket Goto Github PK
View Code? Open in Web Editor NEWSimplify ggplot2 visualisation
Home Page: https://davidhodge931.github.io/ggblanket/
License: Other
Simplify ggplot2 visualisation
Home Page: https://davidhodge931.github.io/ggblanket/
License: Other
Make everything run off scale_*_manual
Ideally it would be:
x_breaks_mid = 0
y_breaks_mid = 0
Titles where no x/y aes
size = 0.5 or size = 1.6 for points
alpha = 0.75
library(ggplot2)
library(palmerpenguins)
ggplot(penguins) +
geom_point(aes(x = body_mass_g, y = flipper_length_mm)) +
scale_x_continuous(breaks = scales::breaks_width(550))
x_breaks <- scales::fullseq(range(penguins$body_mass_g, na.rm = T), size = 550)
gg_point(penguins, body_mass_g, flipper_length_mm,
x_breaks = c( 2200, 2750, 3300, 3850, 4400, 4950, 5500, 6050, 6600))
gg_point(penguins, body_mass_g, flipper_length_mm,
y_breaks = c(160, 190, 240))
x_breaks <- scales::fullseq(range(economics$date, na.rm = T), size = "2 years")
This occurs because the graph is built using ggplot2 default x/y scales
In histogram, the limits affect the data because in histogram the area between the x_limits affects the size of the y values computed.
For all geom's, the build of the ggplot is used to compute the x and y numeric scales. This is because the different positions and stats result in different x and y values.
For gg_histogram, you might have to do something different...
If x is not null, calculate the x_breaks and x_scale based on x_var_vctr, and feed into the ggplot2 build
If y is not null, calculate the y_breaks and y_scale based on the y_var_vctr and feed into the ggplot2
Maybe this should be done in blank??
Default to continuous
Default to col_bins = NULL, which can colour continuously
Choose col_bins = "evenly"
to turn chopping on
"evenly", "quantiles", "mean_sd"
Fine-tune with arg's:
col_intervals = 5
col_probs = seq(0, 1, 0.25)
col_sds = 1:3
col_pretty_n = 5
col_breaks = c(0, 300, 500, 1000)
Might need some work with col_breaks to make it work with gradient
Make it all left, and colour them using nice existing method
gg_blank(penguins,
x = body_mass_g,
y = flipper_length_mm,
dye = sex,
y_zero = TRUE,
position = "fill",
x_limits = c(NA, NA),
) +
geom_col(aes(x = body_mass_g,
y = flipper_length_mm,
col = sex, fill = sex),
position = "fill")
Or should you follow col_method = "gradientn", "manual", "binned"...
"bin" = "b"
"quantile" = "q"
"gradient" = "g"
"category" = "c"
library(ggrescale)
What is the package doing?
1). quick aes: uses quick syntax for aesthetics
2). facet as if an aes: simplifies facetting by treating facet as if it is an aesthetic
3). combines col/fill aes simplifies colour via pal argument, and combining col/fill
4). rescales x/y limits: creates adjustable x and y scales, where limits = min/max breaks
5). reordering: updates order of horizontal geom y and col, including legends, so everything is in order
6). default format: convert labels and titles to sentence case and comma
library(ggremix)
if both x & y numeric, use...
x_limits = c(min(plot_data$year), max((plot_data$year))),
This is because, coord_flip has to be used to have it horizontal where both numeric
For points, lines etc, this would look less good
library(tidyverse)
library(palmerpenguins)
smoother <- function(data, x, y, method = "lm", ...) {
ggplot(data) +
geom_smooth(aes({{x}}, {{y}}), method = method, ...)
}
smoother(penguins, flipper_length_mm, body_mass_g)
smoother(penguins, flipper_length_mm, body_mass_g, method = "loess")
Currently:
x_zero
y_zero
https://ggplot2.tidyverse.org/reference/expand_limits.html
y_limits_include= c(0, 10)
x_limits_include = 0
library(tidyverse)
library(palmerpenguins)
library(ggblanket)
df <- penguins %>%
drop_na(body_mass_g)
breaks_n
breaks_width
scales::fullseq(range(df$body_mass_g), size = 750)
scales::fullseq(range(economics$date), size = "1 year")
dye
colfill
col_fill
No scale present for time
lakers %>%
slice_sample(n = 100) %>%
tibble() %>% select(time, points) %>%
mutate(time = lubridate::hm(time)) %>%
gg_blank(time, points) +
geom_point() +
scale_x_time()
library(palmerpenguins)
library(tidyverse)
plot_data <- storms %>%
group_by(year, status) %>%
summarise(wind = mean(wind, na.rm = T))
plot_data %>%
ggplot(aes(year, wind, col = status)) +
geom_line() +
geom_line(aes(col = "All of NZ"),
data = plot_data %>% group_by(year) %>% summarise(wind = sum(wind)))
More flexible...
but not sure
3 options:
1). Specify an argument, which does it for people.
evenly
...intervals (i.e. col_chop_n = blah) #by width
quantiles
...probs (i.e. col_chop_probs = blah) #by number of elements
mean_sd
..sds (i.e. col_probs_sds = blah) #by statistics
exactly
...breaks (i.e. col_breaks = blah).
pretty
Pro's:
Con's lots of args
penguins %>%
gg_blank(bill_length_mm, flipper_length_mm, body_mass_g, x_zero = F, y_zero = F,
col_labels = ~ prettyNum(.x, big.mark = "", scientific = FALSE),
pal = pal_viridis_reorder(5),
col_chop = ~ santoku::chop_evenly(.x, intervals = 5)
) +
geom_point()
3. Make people do it themselves
From
col_scale_manual
breaks = col_breaks
values = pal
This will need to be clarified in the plot
Also, shortcut functions will get around this...
Ideally it would be:
x_limits_include = c(0)
y_limits_include = c(0)
library(blanket)
-pros: more readable
-cons: not linked to ggplot, unless you know about it, not a name for a leaf wrapper package available
library(ggblanket)
col_legend_place = "r", "t", "b", "n", "m"
Why? Because it is a combo of position/direction/ & title position...
library(tidyverse)
breaks <- c("Chinstrap", "Adelie", "Gentoo", "Another one")
values <- c("green", "blue", "red", "pink")
pal_df <- tibble::tibble(breaks, values)
ggplot(penguins) +
geom_point(aes(flipper_length_mm, body_mass_g, col = species)) +
scale_color_manual(values = pal_df$values, breaks = pal_df$breaks, drop = FALSE)
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.