This is a package containing small utility functions.
You can install the released version of geryon from this Github repo.
remotes::install_github("andrewGhazi/geryon")
Right now this package contains only a handful of functions: ws_size
,
pull1
, get/add_local_density
and theme_pres
.
It’s easy to see the memory usage of a single object with object.size
but doing that in a sorted, pretty way for everything in the workspace
is a bit more involved. This function has taken care of that.
> a = 1:10
> tmp = mtcars
> ws_size()
# A tibble: 2 x 3
obj obj_size n_bytes
<chr> <chr> <int>
1 tmp 6.6 Kb 6736
2 a 88 bytes 88
dplyr::pull
is a convenient way to pull out the values of a column
from a data frame, but if you’ve got a long list column and just want to
check one to make sure everything’s working, printing the whole list can
clutter up the console. pull1
just pulls out one.
> tmp = data_frame(mu = 5:10, samples = purrr::map(mu, ~rnorm(10, mean = .x, sd = 1)))
> tmp
# A tibble: 6 x 2
mu samples
<int> <list>
1 5 <dbl [10]>
2 6 <dbl [10]>
3 7 <dbl [10]>
4 8 <dbl [10]>
5 9 <dbl [10]>
6 10 <dbl [10]>
> tmp %>% pull1(samples)
[1] 4.651063 3.986187 5.421502 4.554197 4.880644 4.511554 5.572671 4.948658 6.132115 5.545000
This is simply a modified version of ggplot2::theme_light
with larger
text and dark facet labels. This makes it easier to prepare easy-to-read
plots for presentations.
diamonds %>% sample_n(1000) %>% ggplot(aes(carat, price)) + geom_point() + theme_pres() + facet_wrap('cut')
This is handy for dealing with severe overplotting in situations where
you still want to plot individual points rather than a density estimate.
You simply give add_local_density
the two variables used in your plot,
then you aesthetically map the resulting local_density
column to
color.
library(ggplot2)
library(magrittr)
overplotted = data.frame(x = rt(1e4, df = 5),
y = rt(1e4, df = 5))
overplotted %>%
ggplot(aes(x,y)) +
geom_point(alpha = .1) +
theme_light() +
labs(title = expression('Intractable overplotting, even with'~alpha~' = 0.1'))
library(geryon)
overplotted %>%
add_local_density(x, y) %>%
ggplot(aes(x,y)) +
geom_point(aes(color = local_density)) + # <-- this is the important bit
theme_light() +
scale_color_viridis_c() +
labs(title = 'Coloring by local density naturally transitions between\nscattered points to a density estimate')
This is a trivial example but sometimes there’s simultaneously important structure hidden in the overplotted region AND important meaning associated with individual points in the sparse outer regions. This sort of plot shows both.
I’m working on a color_density_scatter function that goes straight from the data to the plot.
This function inserts an image link (![](images/blah.png)
) to an image
on your clipboard into the current source document at the cursor. This
way you don’t have to fuss around with the file manager to get images
into your Quarto
report.
It’s provided as an RStudio addin so you can bind a keyboard shortcut to
it. I use Ctrl+Shift+V
.
This function makes some assumptions and currently doesn’t do many checks. There are some caveats:
- It only inserts PNGs. I’ll probably add jpg sooner or later.
- It won’t work if you currently have multiple images on your clipboard.
- It uses xclip to copy from the
image from the clipboard to the
images/
directory. That must be installed. - There must be an
images/
directory in the same directory as the source document. - It doesn’t clean up after itself. If you use it a lot, you might end up with many copies of the same image in your images directory.