UQRUG 24

meeting
Published

February 23, 2022

2022-02-23: UQRUG 24

Attendees

  • Stéphane Guillou: just helping out
  • Svetlina Vasileva
  • Trinh Huynh (USC)
  • Richard Bell
  • Luke Gaiter (ggplot2 lesson)
  • …and 5 other UQRUGers!

Code

Convert a table to a gt object and then save it to RTF (which can be opened by Word).

library(gt)
gt(mtcars) %>% 
  gtsave("test.rtf")

Attempting to highlight/label outliers in linear regression plot

### geom_text_repel
# only label players with QoG >  1 or < 0.2
# align text vertically with nudge_y and allow the labels to 
# move horizontally with direction = "x"
ggplot(linear_regression, aes(x= QOG, y = ten_political_conflict, label = district)) + 
        geom_point(color = dplyr::case_when(linear_regression$QOG > 1 ~ "#1b9e77", 
                                            linear_regression$QOG < 0.2 ~ "#d95f02",
                                            TRUE ~ "#7570b3"), 
                   size = 3, alpha = 0.8) +
        geom_text_repel(data          = subset(linear_regression, QOG > 1),
                        nudge_y       = 32 - subset(linear_regression, QOG > 1)$QOG,
                        size          = 4,
                        box.padding   = 1.5,
                        point.padding = 0.5,
                        force         = 100,
                        segment.size  = 0.2,
                        segment.color = "grey50",
                        direction     = "x") +
        geom_label_repel(data         = subset(linear_regression, QOG < 0.2),
                         nudge_y       = 16 - subset(linear_regression, QOG < 0.2)$QOG,
                         size          = 4,
                         box.padding   = 0.5,
                         point.padding = 0.5,
                         force         = 100,
                         segment.size  = 0.2,
                         segment.color = "grey50",
                         direction     = "x") +
        scale_x_continuous(expand = expansion(mult = c(0.2, .2))) +
        scale_y_continuous(expand = expansion(mult = c(0.1, .1))) +
        theme_classic(base_size = 16)

Shared resources and topics discussed

  • Using Cloudstor’s SWAN: documentation
  • Export tables to DOC or DOCX:
  • forcats has been used twice during the session, once for changing the order of the levels to something arbitrary with forcats::fct_relevel(), and once for ordering them by value (with dplyr::arrange() followed by forcats::fct_inorder())
  • Sustainable transport planning with stplanr
  • lidR moves away from sp/raster and uses sf/terra/stars instead
  • gghighlight was suggested to easily highlight (an label) cases on ggplot2 visualisations