Skip to content

Instantly share code, notes, and snippets.

@vanatteveldt
Created September 12, 2022 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanatteveldt/207d0eb696146475c720824cca69f4a7 to your computer and use it in GitHub Desktop.
Save vanatteveldt/207d0eb696146475c720824cca69f4a7 to your computer and use it in GitHub Desktop.
# Demo 1: Rtweet en word clouds
# install.pacakges("rtweet")
library(tidyverse)
library(rtweet)
library(quanteda)
library(quanteda.textplots)
library(RColorBrewer)
auth_setup_default()
tweets = search_tweets("ukraine", n = 1000, include_rts = FALSE)
tweets |>
corpus() |>
tokens() |>
dfm() |>
textplot_wordcloud(max_words=100)
tweets |>
filter(lang == "en") |>
corpus() |>
tokens() |>
dfm() |>
dfm_remove(min_nchar=2) |>
dfm_remove("ukraine") |>
dfm_remove(stopwords()) |>
textplot_wordcloud(max_words=200, color=brewer.pal(8, "Dark2"),
random_color=TRUE, random_order = TRUE)
# Demo 2: Tidyverse
d = read_csv("https://raw.githubusercontent.com/houstondatavis/data-jam-august-2016/master/csv/county_facts.csv")
# Filter, select, mutate
states = d |> filter(is.na(state_abbreviation), fips != 0) |>
select(fips, area_name, population=Pop_2014_count, pop_change=Pop_change_pct,
white=Race_white_pct, college=Pop_college_grad_pct, income=Income_per_capita) |>
mutate(growing=pop_change>1)
ggplot(states) + geom_point(aes(x=college, y=income))
ggplot(states) + geom_point(aes(x=college, y=income, color=growing))
ggplot(states) + geom_point(aes(x=college, y=income, size=population, color=white), alpha=.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment