July 2021

visualizing topic models with crosstalk

July 12, 2021 | Jason Timm

Introduction A simple post detailing the use of the crosstalk package to visualize and investigate topic model results interactively. As an example, we investigate the topic structure of correspondences from the Founders Online cor... [Read more...]

ggplot: plot only some of the data

July 11, 2021 | R on I Should Be Writing

Often (especially when working with large and/or rich datasets) our (gg)plots can feel cluttered with information. But they don’t have to be! Let’s look at the following plot: Generate some data
library(dplyr)

bfi <- psychTools::bfi %>% 
  mutate(
    O = across(starts_with("O")) %>% rowMeans(na.rm = TRUE),
    C = across(starts_with("C")) %>% rowMeans(na.rm = TRUE),
    E = across(starts_with("E")) %>% rowMeans(na.rm = TRUE),
    A = across(starts_with("A")) %>% rowMeans(na.rm = TRUE),
    N = across(starts_with("N")) %>% rowMeans(na.rm = TRUE)
  ) %>% 
  mutate(
    gender = factor(gender, labels = c("Man", "Woman")),
    education = factor(education, labels = c("HS", "finished HS", "some college", "college graduate", "graduate degree"))
  ) %>% 
  select(gender, education, age, O:N) %>% 
  tidyr::drop_na(education) %>% 
  # multiply the data set
  sample_n(size = 10000, replace = TRUE) %>% 
  # and add some noise
  mutate(across(O:N, \(x) x + rnorm(x, 0, sd(x))))
library(ggplot2)

theme_set(theme_bw())

base_plot <- ggplot(bfi, aes(age, O, color = education)) + 
  facet_wrap(facets = vars(gender)) + 
  coord_cartesian(ylim = c(1, 6)) + 
  scale_color_viridis_d()

base_plot + 
  geom_point(shape = 16, alpha = 0.1) + 
  geom_smooth(se = FALSE)
This is a busy plot. It’s hard to see what the each ...
[Read more...]

ggplot: plot only some of the data

July 11, 2021 | R on I Should Be Writing

Often (especially when working with large and/or rich datasets) our (gg)plots can feel cluttered with information. But they don’t have to be! Let’s look at the following plot: Generate some data
library(dplyr)

bfi <- psychTools::bfi %>% 
  mutate(
    O = across(starts_with("O")) %>% rowMeans(na.rm = TRUE),
    C = across(starts_with("C")) %>% rowMeans(na.rm = TRUE),
    E = across(starts_with("E")) %>% rowMeans(na.rm = TRUE),
    A = across(starts_with("A")) %>% rowMeans(na.rm = TRUE),
    N = across(starts_with("N")) %>% rowMeans(na.rm = TRUE)
  ) %>% 
  mutate(
    gender = factor(gender, labels = c("Man", "Woman")),
    education = factor(education, labels = c("HS", "finished HS", "some college", "college graduate", "graduate degree"))
  ) %>% 
  select(gender, education, age, O:N) %>% 
  tidyr::drop_na(education) %>% 
  # multiply the data set
  sample_n(size = 10000, replace = TRUE) %>% 
  # and add some noise
  mutate(across(O:N, \(x) x + rnorm(x, 0, sd(x))))
library(ggplot2)

theme_set(theme_bw())

base_plot <- ggplot(bfi, aes(age, O, color = education)) + 
  facet_wrap(facets = vars(gender)) + 
  coord_cartesian(ylim = c(1, 6)) + 
  scale_color_viridis_d()

base_plot + 
  geom_point(shape = 16, alpha = 0.1) + 
  geom_smooth(se = FALSE)
This is a busy plot. It’s hard to see what the each ...
[Read more...]

simplevis: making leaflet sf maps

July 11, 2021 | David Hodge

Introduction In addition to gglot2 wrapper functions, simplevis also provides leaflet wrapper functions as a bonus. The way these functions have been designed is to follow the logic of the ggplot2 wrapper functions.
library(simplevis)
library(dplyr)
library(palmerpenguins)
sf objects The sf package makes it easy to work with vector data (e.g. points, ...
[Read more...]

GooglyPlusPlus2021 adds new bells and whistles!!

July 11, 2021 | Tinniam V Ganesh

This latest update of GooglyPlusPlus2021 includes new controls which allow for granular analysis of teams and matches. This version includes a new ‘Date Range’ widget which will allow you to choose a specific interval between which you would like to analyze data. The Date Range widget has been added to 2 ...
[Read more...]

Ellsberg’s Paradox

July 10, 2021 | R on Harshvardhan

I was reading the book “How Not to Be Wrong: The Power of Mathematical Thinking” by Jordan Ellenberg. The book introduces a paradox named after Daniel Ellsberg, a young analyst at RAND Corporation and famous for leaking the Pentagon papers ...
[Read more...]
1 5 6 7 8 9 10

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)